- Home /
freeze position on click
I need help making my trampolines freeze after i click a cube. how my game works is theres two portals the start and end portal and your goal is to bounce a ball from one portal (the start portal) to the next (end portal) by bouncing it off of trampolines but my point is the trampolines are going to be lined up to where you want it then you click the cue releasing the ball but people could just guide the ball to the end portal so my goal is to make the trampolines freeze when they click the cube i've started a script already though that hasn't been working out can you please give me my problem and a solution or a different script to work.
here's the script:
var cube : Transform;
function OnMouseDown()
{
transform.Translate (500,500,500);
}
function OnMouseUp()
{
cube.MovePoint2.enable = false;
}
Answer by bam191 · Aug 19, 2013 at 09:06 PM
What you want is:
function Update()
{
if(Input.GetMouseButtonDown("0")){
//code for trampolines to stop moving
//this if statement is only triggered when the user clicks the mouse 0 button (left click by default)
}
}
That code will check if the player is pressing the mouse button, and you can make it freeze the trampolines simply by stopping their movement.
And i forgot to mention i have a drag and drop script that lets people move the trampolines seperetaly.
this is the drag and drop script:
private var screenPoint: Vector3; private var offset: Vector3; private var curScreenPoint : Vector3; private var curPosition : Vector3;
function Start () { }
function Update () { }
function On$$anonymous$$ouseDown () { screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position); offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); Screen.showCursor = false; }
function On$$anonymous$$ouseDrag() { curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset; transform.position = curPosition; }
function On$$anonymous$$ouseUp(){ Screen.showCursor = true; }
no you drag them to set up the course so the ball bounces off them and i want it so that once you release the ball you can move the trampolines anymore