Commit d532a711 authored by christopher.foster's avatar christopher.foster

Upload New File

parent 3437aee6
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
enum State
{
left,
right
}
public class finiteStateMachine : MonoBehaviour
{
private State _state;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
switch (this._state)
{
case State.left:
moveLeft();
break;
case State.right:
moveRight();
break;
}
}
void moveLeft()
{
transform.position = new Vector3(transform.position.x + 1.0f * Time.deltaTime, transform.position.y, transform.position.z);
if (transform.position.x < 10)
{
this._state = State.right;
}
}
void moveRight()
{
transform.position = new Vector3(transform.position.x - 1.0f * Time.deltaTime, transform.position.y, transform.position.z);
if (transform.position.x > -10)
{
this._state = State.left;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment