// Update is called once per frame void Update() { GlobalBehavior.WorldBoundStatus status = mGameManager.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { Destroy(this.gameObject); } }
// Update is called once per frame void Update() { transform.position += (200f * Time.smoothDeltaTime) * transform.up; status = globalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { NewDirection(); } }
// Update is called once per frame void Update() { transform.position += (mSpeed * transform.up * Time.smoothDeltaTime); GlobalBehavior.WorldBoundStatus status = mGameManager.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { mGameManager.subtractEggCount(); Destroy(this.gameObject); } }
// Update is called once per frame void Update() { heroDiff = hero.transform.position - transform.position; heroDot = Vector2.Dot(heroDiff, -hero.transform.up); if (state == stateType.Default) { if (heroDiff.magnitude < maxScare && heroDot > 0) { state = stateType.Afraid; renderer.sprite = spriteAfraid; } transform.position += (mSpeed * Time.smoothDeltaTime) * transform.up; } else if (state == stateType.Stunned) { mRotation = transform.rotation.eulerAngles; mRotation.z += (9 * Time.deltaTime); transform.rotation = Quaternion.Euler(mRotation); stunTimer += Time.deltaTime; if (stunTimer > stunDuration) { state = stateType.Default; renderer.sprite = spriteDefault; } } else if (state == stateType.Afraid) { if (heroDiff.magnitude > maxScare || heroDot < 0) { state = stateType.Default; renderer.sprite = spriteDefault; } run = (mSpeed * .2f * Time.smoothDeltaTime) * (-1 * heroDiff).normalized; transform.position += run; //transform.rotation = Quaternion.AngleAxis(rotateAngle, transform.forward); var angle = Mathf.Atan2(run.y, run.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, transform.forward); transform.Rotate(Vector3.forward * -90); } status = globalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { NewDirection(); } }
// Update is called once per frame void Update() { transform.position += (mSpeed * Time.smoothDeltaTime) * transform.up; status = globalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { // Debug.Log("collided position: " + this.transform.position); GameObject e = Instantiate(mSplash, transform.position, Quaternion.Euler(0, 0, Random.Range(0, 360))) as GameObject; Destroy(gameObject); } }
// Update is called once per frame void Update() { transform.position += (mSpeed * Time.smoothDeltaTime) * transform.up; GlobalBehavior globalBehavior = GameObject.Find("GameManager").GetComponent <GlobalBehavior>(); GlobalBehavior.WorldBoundStatus status = globalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { // Debug.Log("collided position: " + this.transform.position); NewDirection(); } }
private void BoundPosition() { GlobalBehavior.WorldBoundStatus status = GlobalBehavior.sTheGlobalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); switch (status) { case GlobalBehavior.WorldBoundStatus.CollideBottom: case GlobalBehavior.WorldBoundStatus.CollideTop: transform.up = new Vector3(transform.up.x, -transform.up.y, 0.0f); break; case GlobalBehavior.WorldBoundStatus.CollideLeft: case GlobalBehavior.WorldBoundStatus.CollideRight: transform.up = new Vector3(-transform.up.x, transform.up.y, 0.0f); break; } }
// Update is called once per frame void Update() { #region user movement control transform.position += Input.GetAxis("Vertical") * transform.up * (kHeroSpeed * Time.smoothDeltaTime); status = globalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { transform.position -= 3 * Input.GetAxis("Vertical") * transform.up * (kHeroSpeed * Time.smoothDeltaTime); } transform.Rotate(Vector3.forward, -1f * Input.GetAxis("Horizontal") * (kHeroRotateSpeed * Time.smoothDeltaTime)); #endregion if (Input.GetAxis("Fire1") > 0f) // this is Left-Control { GameObject e = Instantiate(mProjectile) as GameObject; EggBehavior egg = e.GetComponent <EggBehavior>(); // Shows how to get the script from GameObject if (null != egg) { worldOffset = transform.rotation * offset; e.transform.position = transform.position + worldOffset; egg.SetForwardDirection(transform.up); } } }
// Update is called once per frame void Update() { // Get the position of the target waypoint Vector2 target = waypoints[curDestination].transform.position; // Get the direction the enemy needs to point Vector3 targetDirection = waypoints[curDestination].transform.position - transform.position; // Move towards the waypoint transform.position = Vector2.MoveTowards(transform.position, target, mSpeed * Time.smoothDeltaTime); // Rotate towards the waypoint transform.up = Vector3.RotateTowards(transform.up, targetDirection, mSpeed * Time.smoothDeltaTime, 0.0f); // Check if enemy hit world bounds GlobalBehavior.WorldBoundStatus status = globalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { Debug.Log("collided position: " + this.transform.position); NewDirection(); } }
// Update is called once per frame void Update() { // Clamp GlobalBehavior.WorldBoundStatus status = mGameManager.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != GlobalBehavior.WorldBoundStatus.Inside) { NewDirection(); } //State Change #region State Change Vector3 toHero = transform.position - mHero.transform.position; float dot = Vector3.Dot(toHero, mHero.transform.up); if (mState == EnemyState.Stunned && Time.realtimeSinceStartup - mTimeStunned < kStunnedDuration) { mState = EnemyState.Stunned; if (null != mRenderder) { mRenderder.sprite = Resources.Load("Textures/stunned_student", typeof(Sprite)) as Sprite; } } else { if (toHero.magnitude <= 30.0f && dot > 0) // RUN { if (mState != EnemyState.Run) { var source = GetComponents <AudioSource>(); AudioSource no = source[1]; no.Play(); } mState = EnemyState.Run; if (null != mRenderder) { mRenderder.sprite = Resources.Load("Textures/running_student", typeof(Sprite)) as Sprite; } } else if (mState == EnemyState.Scary || wasScary) { mState = EnemyState.Scary; if (null != mRenderder) { mRenderder.sprite = Resources.Load("Textures/scary_student", typeof(Sprite)) as Sprite; } } else // Normal { mState = EnemyState.Normal; if (null != mRenderder) { mRenderder.sprite = Resources.Load("Textures/student", typeof(Sprite)) as Sprite; } } } #endregion // Movement #region movements if (mState == EnemyState.Normal || mState == EnemyState.Scary) { Move(); } else if (mState == EnemyState.Run) { RunAway(); } else { Rotate(); } #endregion }