// Update is called once per frame void Update() { #region User Position Control transform.position += Input.GetAxis("Vertical") * transform.up * (kHeroSpeed * Time.smoothDeltaTime); transform.position += Input.GetAxis("Horizontal") * transform.right * (kHeroSpeed * Time.smoothDeltaTime); #endregion #region Testing the Camera Support: Push and Collision Bound mTheCamera.PushCameraByPos(transform.position, WorldBoundRegion); // testing the intersection CameraSupport.WorldBoundStatus status = mTheCamera.CollideWorldBound(GetComponent <Renderer>().bounds, WorldBoundRegion); // Debug.Log("Hero Collision=" + status); #endregion #region Testing TimedLerp: using size if (Input.GetKeyDown(KeyCode.Z)) { Vector3 finalScale = transform.localScale; transform.localScale += new Vector3(kDeltaSize, kDeltaSize, 0f); mSizeLerp.SetLerpParms(mDuration.value(), mRate.value()); mSizeLerp.BeginLerp(transform.localScale, finalScale); } if (mSizeLerp.LerpIsActive()) { Vector3 s = mSizeLerp.UpdateLerp(); transform.localScale = new Vector3(s.x, s.y, 0.0f); } #endregion }
// Update is called once per frame void Update() { Vector3 p = transform.localPosition; if (Input.GetKeyDown(KeyCode.Space)) { mFollowMousePosition = !mFollowMousePosition; } if (mFollowMousePosition) { p = Camera.main.ScreenToWorldPoint(Input.mousePosition); p.z = 0f; // <-- this is VERY IMPORTANT! // Debug.Log("Screen Point:" + Input.mousePosition + " World Point:" + p); } else { if (Input.GetKey(KeyCode.W)) { p += ((mHeroSpeed * Time.smoothDeltaTime) * transform.up); } if (Input.GetKey(KeyCode.S)) { p -= ((mHeroSpeed * Time.smoothDeltaTime) * transform.up); } if (Input.GetKey(KeyCode.A)) { transform.Rotate(transform.forward, mHeroRotateSpeed * Time.smoothDeltaTime); } if (Input.GetKey(KeyCode.D)) { transform.Rotate(transform.forward, -mHeroRotateSpeed * Time.smoothDeltaTime); } CameraSupport s = Camera.main.GetComponent <CameraSupport>(); // Try to access the CameraSupport component on the MainCamera if (s != null) // if main camera does not have the script, this will be null { Bounds myBound = GetComponent <Renderer>().bounds; // this is the bound of the collider defined on GreenUp CameraSupport.WorldBoundStatus status = s.CollideWorldBound(myBound); if (status != CameraSupport.WorldBoundStatus.Inside) { Debug.Log("Touching the world edge: " + status); // now let's re-spawn ourself somewhere in the world p.x = s.GetWorldBound().min.x + Random.value * s.GetWorldBound().size.x; p.y = s.GetWorldBound().min.y + Random.value * s.GetWorldBound().size.y; } } } transform.localPosition = p; }
// Update is called once per frame void Update() { CameraSupport.WorldBoundStatus status = mTheCamera.CollideWorldBound(GetComponent <Renderer>().bounds, WorldRegion); // Debug.Log("BoundCollisionStatus = " + status); if (status != CameraSupport.WorldBoundStatus.Inside) { mTheCamera.ClampToWorldBound(transform, WorldRegion); } }
// Update is called once per frame void Update() { transform.position += Input.GetAxis("Vertical") * transform.up * (kHeroSpeed * Time.smoothDeltaTime); transform.position += Input.GetAxis("Horizontal") * transform.right * (kHeroSpeed * Time.smoothDeltaTime); mTheCamera.PushCameraByPos(transform.position, WorldBoundRegion); // testing the intersection CameraSupport.WorldBoundStatus status = mTheCamera.CollideWorldBound(GetComponent <Renderer>().bounds, WorldBoundRegion); Debug.Log("Hero Collision=" + status); }
// Update is called once per frame void Update() { Vector3 p = transform.localPosition; if (Input.GetKey(KeyCode.W)) { p.y += kDelta; } if (Input.GetKey(KeyCode.S)) { p.y -= kDelta; } if (Input.GetKey(KeyCode.A)) { p.x -= kDelta; } if (Input.GetKey(KeyCode.D)) { p.x += kDelta; } // 1. Find the main camera and get the CameraSupport component CameraSupport s = Camera.main.GetComponent <CameraSupport>(); // Try to access the CameraSupport component on the MainCamera if (s != null) // if main camera does not have the script, this will be null { // intersect my bond with the bounds of the world Bounds myBound = GetComponent <Renderer>().bounds; // this is the bound on the SpriteRenderer CameraSupport.WorldBoundStatus status = s.CollideWorldBound(myBound); // If result is not "inside", then, move the hero to a random position if (status != CameraSupport.WorldBoundStatus.Inside) { Debug.Log("Touching the world edge: " + status); // now let's re-spawn ourself somewhere in the world p.x = s.GetWorldBound().min.x + Random.value * s.GetWorldBound().size.x; p.y = s.GetWorldBound().min.y + Random.value * s.GetWorldBound().size.y; } } transform.localPosition = p; }
public CameraSupport.WorldBoundStatus CollideWorldBound(Bounds b) { return(mMainCamera.CollideWorldBound(b)); }