- Home /
Question by
mustang4484 · Mar 09, 2019 at 06:02 PM ·
instantiateraycastprefablookat
Instantiate prefab from original position to click mouse point position
Hi guys
I've this script where i would like to instantiate a prefab from orig.position to mouse click position; I don't know if to use a rotate towards it's a good idea after the instance.
Thank you
void Update()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (Input.GetMouseButtonDown(0))
{
//GameObject obj = Instantiate(prefab, new Vector3(hit.point.x, 2, hit.point.z), Quaternion.identity) as GameObject;
Vector3 dir = new Vector3(hit.point.x, 0, hit.point.z);
GameObject bullet = Instantiate(prefab, orig.transform.position, Quaternion.Euler(0,0,90)) as GameObject;
//bullet.GetComponent<Rigidbody>().velocity = transform.forward * bulletSpeed;
bullet.transform.LookAt(dir, Vector3.forward);
}
Comment
Your answer
Follow this Question
Related Questions
Instantiating prefab question. 1 Answer
Instantiate a prefab and parenting it? 1 Answer
The prefab you want to instantiate is null. 4 Answers
A way to instantiate an item with 90 Degree increments? 2 Answers
Throw stuff! Instantiate preFab from game object to raycast point, at least I'd like to. 1 Answer