Want to make my object move in a different direction after mouse click.

my object moves form the center to the right.on mouse click it goes back to the center. I want the object to now start moving in a random direction after that, and on mouse clicks still go back to the center.

#pragma strict

function Start () {
Debug.Log (“Start”);
}

function Update () {
Debug.Log (“Update”);

transform.position.x = transform.position.x + 0.01;

if(Input.GetMouseButton(0)){
	transform.position.x = 0;
	
if(){
	transform.position.x = transform.position.x - 0.01;
		
}

}

There are several ways in which to do this. I don’t know how random you want it to be… SO my personal favorite method would be…

function OnMouseDown(){
       //Set your gameobject to this variable
       var gameObject : GameObject;
       gameObject.AddExplosiveForce;
}

If my knowledge of Unity physics are correct this will launch you in whatever way it chooses. But as there are always more than one solution… and if you don’t find this one satisfactory, I can provide others.

Debug.Log(FriendlySalutation);