- Home /
Script block animations and other scripts
#pragma strict
var wnCanvas : Canvas;
function Update () {
if (transform.position == Vector3(0, 100, 0))
(gameObject.Find("fpc").GetComponent("MouseLook") as MonoBehaviour).enabled = false;
(gameObject.Find("Main Camera").GetComponent("MouseLook") as MonoBehaviour).enabled = false;
wnCanvas.enabled = true;
Time.timeScale = 0;
Screen.lockCursor = false;
Screen.showCursor = true;
GameObject.Find("fpc").audio.volume = 0.5;
GameObject.Find("fpc").GetComponent(fst_mo).enabled = false;
GameObject.Find("fpc").GetComponent(slw_mo).enabled = false;
GameObject.Find("Main Camera").GetComponent(cmr_zm).enabled = false;
}
But if I attach him to First Person Controller my animations and scripts doesn´t work. What´s wrong with this script?
So your issue is that this script disables script and animations on your First Person Controller?
Well that is exactly what is is doing, it is disabling the mouselook controller, the motion controllers, the camera. So apart from being extremely inefficient because it calls Find functions in the Update loop, there is not much else wrong.
Although it will most likely not disable the scripts at all because it is very unlikely that transform.position will ever be exactly equal to Vector3(0, 100, 0).
We might need some more information on what you are trying to achieve to be able to help you better.
From what i understand you want to disable components and pause game when player reaches Vector3(0, 100, 0)
If so, put your code below If statement within curly braces.
At the moment your script executes following code when If statement is true because of missing curly braces.
(gameObject.Find("fpc").GetComponent("$$anonymous$$ouseLook") as $$anonymous$$onoBehaviour).enabled = false;
All other code is executed every frame.
Since you execute Time.timeScale = 0; every frame.Your animations have stopped and so have other objects which depend on time.
Answer by Mangas · Jan 07, 2015 at 12:03 PM
The problem is that Time.timeScale is 0, so your game is basically paused.
Answer by alok-kr-029 · Jan 07, 2015 at 09:36 AM
Time.timeScale = 1;
I am not sure but looks you have changed the time scale to zero