Question by
connordunn545 · Dec 28, 2020 at 06:16 AM ·
scripting beginnerscript error
trying to make a cube spawn on player mouse position?
{ public Vector3 mousep;
void Start()
{
}
void Update()
{
mousep = Input.mousePosition;
Debug.Log(mousep);
if (Input.GetMouseButtonDown(1))
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = new Vector3();
}
}
}
however I cant use the variable in the new Vector3 so what do I do?
Comment
Answer by tomashevskiysergiy · Dec 28, 2020 at 07:35 PM
public Camera camera; RaycastHit hit; Ray ray = gameCamera.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray,out hit)) { Instantiate... }
Instantiate function: https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
Your answer
Follow this Question
Related Questions
Accessing script from another object 1 Answer
BCE0044: expecting ''', found '\r'. 1 Answer
Unity {[(2D)]} RotateAround while jumping 0 Answers