I am trying to create a script that shoots a prefab towards the mouse in a 2D environment, when the mouse is clicked on the left side of the player it works, when it is clicked on the right player the prefab spawns then vanishes. This doesnt really make any sense to me, any ideas?
#pragma strict
var prefab : GameObject;
var distance = 100;
function Update () {
if (Input.GetMouseButtonDown(0)) {
var position = Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
position = Camera.main.ScreenToWorldPoint(position);
var go = Instantiate(prefab, transform.position, Quaternion.identity) as GameObject;
go.transform.LookAt(position);
Debug.Log(position);
go.rigidbody2D.AddForce(go.transform.forward * 1000);
}
}