// Use this for initialization void Start() { spawnManager = GameObject.FindGameObjectWithTag("SpawnManager"); parentOriginalPosition = transform.position; if (spawnManager.GetComponent <SpawnManager>().canMoreEnemiesSpawn&& spawnManager.GetComponent <SpawnManager>().canUrchinSpawn) { currentState = UrchinStates.SPAWNING; spawnManager.GetComponent <SpawnManager>().SpawnEnemy(); } }
// Update is called once per frame void Update() { switch (currentState) { case UrchinStates.SPAWNING: transform.position = parentOriginalPosition; currentState = UrchinStates.MOVING; break; case UrchinStates.MOVING: if (isUrchinShrunk && Time.time > shrunkenTimeStamp + maxTimeAllowedShrunken) { isUrchinShrunk = false; transform.localScale = new Vector3(maxScaleSize, maxScaleSize, maxScaleSize); extendAudio.Play(); } transform.position = Vector3.MoveTowards(transform.position, urchinDestination.transform.position, movementSpeed * Time.deltaTime); if (Vector3.Distance(transform.position, urchinDestination.transform.position) < 1) { //transform.position = parentOriginalPosition; spawnResetTimeStamp = Time.time; currentState = UrchinStates.WAITING; spawnManager.GetComponent <SpawnManager>().DestroyEnemy(); } break; case UrchinStates.WAITING: if (spawnManager.GetComponent <SpawnManager>().canMoreEnemiesSpawn&& spawnManager.GetComponent <SpawnManager>().canUrchinSpawn&& Time.time > spawnResetTimeStamp + spawnMaxTime) { currentState = UrchinStates.SPAWNING; spawnManager.GetComponent <SpawnManager>().SpawnEnemy(); } break; } }