void OnGameStart() { _enabled = true; _curState = UFOState.Idle; startTime = Time.time; waitTime = Random.Range(minWaitTime, maxWaitTime); }
IEnumerator PerformState(UFOState state, float lengthInSeconds) { isExecutingState = true; currentState = state; float stateRemaining = 0.0f; while (stateRemaining < lengthInSeconds) { switch (currentState) { case UFOState.Stopped: break; case UFOState.Observing: Observe(); break; case UFOState.Moving: Move(); break; } stateRemaining += Time.deltaTime; yield return(null); } currentState = nextState; isExecutingState = false; }
void dropPucks() { int puckCount = Random.Range(minItems, maxItems); for (int i = 0; i < puckCount; i++) { float randType = Random.value; if (randType < movingChance) { Instantiate(movingPuck, transform.position + new Vector3(randType / 10, randType / 10, 0), Quaternion.identity); } else if (randType < movingChance + explodingChance) { Instantiate(explodingPuck, transform.position + new Vector3(randType / 10, randType / 10, 0), Quaternion.identity); } else { Instantiate(basicPuck, transform.position + new Vector3(randType / 10, randType / 10, 0), Quaternion.identity); } } waitTime = 1; startTime = Time.time; _curState = UFOState.Dropping; }
private void UpdateCircleAndShootState() { if (Vector3.Distance(this.transform.position, player.transform.position) > movingDistance + 5) { state = UFOState.MoveTowards; } CircleAroundPlayer(); }
void SpawnUFO() { Instantiationtimer -= Time.deltaTime; if (Instantiationtimer <= 0) { //Step 1: assign the new ufo created below to the spawnedUFO variable spawnedUFO = Instantiate(uFo, new Vector3(-0, -0, -11), Quaternion.identity); Instantiationtimer = 5f; state = UFOState.Waiting; } }
public IEnumerator MoveToSpace() { CurrentState = UFOState.MoveToSpace; StopHunting(); while (transform.position != StartPosition) { transform.position = Vector3.MoveTowards(transform.position, StartPosition, Speed * Time.deltaTime); yield return(new WaitForEndOfFrame()); } CurrentState = UFOState.InSpace; Audio.Stop(); }
//Use this for initialization void Start() { if (Random.value > 0.5) { rotationDirection = 1; } else { rotationDirection = -1; } state = UFOState.MoveTowards; player = GameObject.FindGameObjectWithTag("Player"); }
public IEnumerator MoveToPoint(Vector3 point) { CurrentState = UFOState.MoveToIsland; Audio.clip = IdleSound; Audio.volume = 0.75f; Audio.Play(); while (transform.position != point) { transform.position = Vector3.MoveTowards(transform.position, point, Speed * Time.deltaTime); yield return(new WaitForEndOfFrame()); } CurrentState = UFOState.OnIsland; CheckCurrentTerrain(); OnMovedToIsland(); }
// Update is called once per frame void Update() { if (state == UFOState.Spawning) { SpawnUFO(); } else if (state == UFOState.Waiting) { //step 2: check if the spawnedUFO variable is empty, using a null check if (spawnedUFO == null) { state = UFOState.Spawning; } //step 3: if the spawnedUFO variable is empty, change the UFO state to spawning } }
void moveToDropPoint() { ufoTrail.enabled = false; GetComponent <AudioSource>().PlayOneShot(ufoSound); int dropPoint = Random.Range(0, dropPoints.Count - 1); startPoint = Random.Range(0, startPoints.Count - 1); transform.position = startPoints[startPoint].position; targetPos = dropPoints[dropPoint].position; ufoTrail.enabled = true; entering = true; _curState = UFOState.MovingToDrop; }
private void UpdateMoveState() { if (player && Vector3.Distance(this.transform.position, player.transform.position) <= Random.Range(movingDistance - 5, movingDistance + 5)) { state = UFOState.CircleAndShoot; //determine rotation direction if (Random.value > 0.5) { rotationDirection *= -1; } //stop approach GetComponent <Rigidbody>().drag = 1000; //rotationSpeed *= 2; } MoveToPlayer(); }
void move() { float step = moveSpeed * Time.deltaTime; transform.position = Vector2.MoveTowards(transform.position, targetPos, step); float distance = Vector2.Distance(transform.position, targetPos); if (distance < 1) { if (entering) { entering = false; dropPucks(); } else { entering = true; waitTime = Random.Range(minWaitTime, maxWaitTime); _curState = UFOState.Idle; } } }
void leaveDropPoint() { switch (startPoint) { case 0: targetPos = startPoints[2].position; break; case 1: targetPos = startPoints[3].position; break; case 2: targetPos = startPoints[0].position; break; case 3: targetPos = startPoints[1].position; break; } entering = false; _curState = UFOState.MovingToIdle; }
void Awake() { StartPosition = transform.position; CurrentState = UFOState.InSpace; }
private void OnBecameInvisible() { state = UFOState.Stop; }
private void OnBecameVisible() { state = UFOState.Moving; }