- Home /
How to stop my character from moving when mouse is clicked.
I am trying to build a simple game where a character falls from the sky and the player clicks on it to destroy it. I am just learning how to use unity and all the commands that come with it but I know how to code. Right now I have written a script to allow the character to fall from the sky in a loop and want it to stop when I click on it. Once I learn that I'm sure I can get the rest. Here's my code: #pragma strict
var pointB : Vector3;
var freeze = true;
function Start ()
{
var pointA = transform.position;
while (!freeze)
{
yield MoveObject(transform, pointA, pointB, 3.0);
}
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float)
{
var i = 0.0;
var rate = 1.0/time;
while (i < 1.0)
{
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}
function Update() {
if(Input.GetMouseButtonDown(0))
destroy();
}
function destroy()
{
freeze = false;
}
The character continuously falls just fine but doesn't stop when I click on it. Am I doing something wrong?
Answer by Maui-M · Feb 17, 2014 at 10:14 PM
function destroy()
{
freeze = true;
}
Thanks $$anonymous$$aui $$anonymous$$. that fixed it. Now though it seems that no matter where I clicked on the screen it works. I want it to only work when clicking on the character. I put the script into the location of the character.
Your answer
Follow this Question
Related Questions
How to have animation play correctly 1 Answer
clone functions 2 Answers
How do i deactivate a GameObject from js 1 Answer
accessing a variable from one script in another with Unity 1 Answer
GuiTexture For Jump A Character 0 Answers