- Home /
Stop running script when object is selected.
Hey! Iv'e got a problem, i can't seem to be able to stop running a script as i select the object, and then when i select a other object i want i the start running the script again. I am using raycast to select object, like this:
var objektnamn : String;
function Update () { if ( Input.GetMouseButtonDown(1) ) { var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, hit, 1000.0)) { Debug.Log(hit.collider.gameObject.name); objektnamn = hit.collider.gameObject.name; } }
if ( objektnamn == this.gameObject.name ) { var speed = 9.0; var rotateSpeed = 9.0; var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") rotateSpeed, 0); var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed); } }
And i woud like to stop the Al.js script (Waypoint script) when a certain object i selected. Hope you understand, maybe i messed up? Apriciating answers A LOT! Thanks in advance! Sorry for poor english... //Tommy
Answer by kennypu · Feb 14, 2011 at 07:44 PM
I'm not quite sure what you're asking, but if you want to disable a script, set its enabled property to false. so like GetComponent(CharacterController).enabled = false;
Your answer
Follow this Question
Related Questions
Stop play procedure from within a script 0 Answers
New Game & Quit Game in 1 script 1 Answer
How to stop game from running in editor 1 Answer
Simple Walking/Running Script 1 Answer
Spawn object problem 1 Answer