// Update is called once per frame void Update() { transform.position += (mSpeed * transform.up * Time.smoothDeltaTime); lvl1_GB.WorldBoundStatus status = mGameManager.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != lvl1_GB.WorldBoundStatus.Inside) { mGameManager.subtractEggCount(); Destroy(this.gameObject); } }
void OnTriggerEnter2D(Collider2D other) { var source = GetComponents <AudioSource>(); AudioSource blast = source[0]; AudioSource no = source[1]; AudioSource bite = source[2]; if (other.gameObject.name == "lvl1_egg(Clone)") { mHits++; blast.Play(); if (mHits > 2) // 3 hits and die { mGameManager.subtractEnemyCount(); mGameManager.scoreIncrease(); Destroy(this.gameObject); } else // stunned { mTimeStunned = Time.realtimeSinceStartup; mState = EnemyState.Stunned; if (null != mRenderder) { mRenderder.sprite = Resources.Load("Textures/stunned_student", typeof(Sprite)) as Sprite; } } mGameManager.subtractEggCount(); Destroy(other.gameObject); } else if (other.gameObject.name == "lvl1_apple(Clone)") { bite.Play(); mHits -= 3; mState = EnemyState.Scary; wasScary = true; if (null != mRenderder) { mRenderder.sprite = Resources.Load("Textures/scary_student", typeof(Sprite)) as Sprite; } Destroy(other.gameObject); } }