- Home /
Question by
GreenTitan · May 14, 2014 at 12:56 PM ·
rotationgameobjectinstantiatespritequaternion
Rotating a sprite toward the mouse position on instantiation.
Ok. So I want to instantiate a laser bullet upon a mouse click. The laser bullet should be rotated towards the mouse position upon mouse click. But instead they do not rotate.
laserbullet1 is a spriterenderer gameObject.
This is the script.
pragma strict
var laserbullet1 : GameObject;
function Start() {
}
function Update()
{
Shoot();
}
function Shoot() { if( Input.GetMouseButtonDown(0))
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
var LookRotation : Vector3;
if(Physics.Raycast(ray,hit))
{
LookRotation = hit.transform.position;
}
Instantiate( laserbullet1 , transform.position + (transform.right/4), Quaternion.LookRotation(LookRotation));
}
}
Comment