0% found this document useful (0 votes)
8 views2 pages

Mover Cs

mover

Uploaded by

Abhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Mover Cs

mover

Uploaded by

Abhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System.

Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Mover the game object back and forth
/// </summary>
public class Mover : MonoBehaviour
{
#region Fields

// don't change any of these fields!

const float MoveAmountPerSecond = 5;


const float TimerDuration = 1;

// direction-changing support
Timer directionTimer;
int directionMultiplier = 1;

#endregion

#region Properties - for autograder use only!

/// <summary>
/// Gets and sets the position of the game object
/// </summary>
public Vector3 Position
{
get { return transform.position; }
set { transform.position = value; }
}

/// <summary>
/// Gets the direction timer so the autograder can
/// update the timer every frame
/// </summary>
public Timer DirectionTimer
{
get { return directionTimer; }
}

#endregion

#region Unity methods

/// <summary>
/// Start is called before the first frame update
/// </summary>
public void Start()
{
// set position of game object for autograder
transform.position = new Vector3(-2.5f, 0, 0);

// add and run the timer


directionTimer = gameObject.AddComponent<Timer>();
directionTimer.Duration = TimerDuration;
directionTimer.Run();
}
/// <summary>
/// Update is called once per frame
/// </summary>
public void Update()
{
// change direction as appropriate
if (directionTimer.Finished)
{
directionMultiplier *= -1;
directionTimer.Run();
}

// move game object


transform.position += new Vector3(directionMultiplier *
MoveAmountPerSecond * Time.deltaTime, 0 ,0);
}

#endregion
}

You might also like