Note that there are some explanatory texts on larger screens.

plurals
  1. POFreeze camera for 3 seconds in Unity3D (C#)
    primarykey
    data
    text
    <p>I'm trying to make the camera freeze for 3 seconds when the player scrolls to the left or right. I've got the code working to scroll back as soon as you move the mouse back, but there must be a 3 second delay. Here's that I've got:</p> <pre><code>using UnityEngine; using System.Collections; public class CamCont : MonoBehaviour { public float LockedY = 1; public float LockedZ = -7; public GameObject player; private bool edgeRightMouse = false; private bool edgeLeftMouse = false; private float backLeft = -0.3f; private float backRight = 0.3f; private bool backLStrife = false; private bool backRStrife = false; private float freezeOn = 0.0f; private float freezeUntil = 3.0f; private float plusSpeed = 0.1f; private float minusSpeed = -0.1f; public float sensitivityX = 1f; public float horizontalMouseRight = 1014; public float horizontalMouseLeft = 10; public float moveRightUntil = 20; public float moveLeftUntil = -20; float mHdg = 0f; float mPitch = 0f; void Start() { //:P } void Update() { if (Input.mousePosition.x &gt; horizontalMouseRight) { if (transform.position.x &lt; moveRightUntil) { Strafe (plusSpeed); edgeRightMouse = true; } } else edgeRightMouse = false; if (transform.position.x &gt; player.transform.position.x &amp;&amp; !edgeRightMouse) { /*if (backLStrife == false) { freezeOn &gt;= Time.deltaTime; if (freezeOn &gt;= freezeUntil) { backLStrife = true; } }*/ if (backLStrife == false) backLStrife = true; if (backLStrife == true) Strafe (backLeft); if (transform.position.x - player.transform.position.x &lt; backRight) backLStrife = false; } if (Input.mousePosition.x &lt; horizontalMouseLeft) { if (transform.position.x &gt; moveLeftUntil) { Strafe (minusSpeed); edgeLeftMouse = true; } } else edgeLeftMouse = false; if (transform.position.x &lt; player.transform.position.x &amp;&amp; !edgeLeftMouse) { if (backRStrife == false &amp;&amp; freezeOn &gt;= freezeUntil) backRStrife = true; if (backRStrife == false) backRStrife = true; if (backRStrife == true) Strafe (backRight); if (transform.position.x + player.transform.position.x &gt; backLeft) backRStrife = false; } if (!backLStrife &amp;&amp; !backRStrife &amp;&amp; !edgeLeftMouse &amp;&amp; !edgeRightMouse &amp;&amp; freezeOn &gt; 0) transform.position = new Vector3(player.transform.position.x, LockedY, LockedZ); Debug.Log (Input.mousePosition); } void Strafe(float aVal) { transform.position += aVal * transform.right; } void ChangeHeading(float aVal) { mHdg += aVal; WrapAngle(ref mHdg); transform.localEulerAngles = new Vector2(mPitch, mHdg); } public static void WrapAngle(ref float angle) { if (angle &lt; -360f) angle += 360f; if (angle &gt; 360f) angle -= 360f; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload