- Home /
Question by
Domo23000 · Aug 20, 2014 at 08:44 PM ·
camerainstantiatevector3mousepositionscreentoworldpoint
Camera ScreenToWorldPoint Instatiating
I need a little help on a problem i have. i want to place an object in 2d space at my mouse position, so i used ScreenToWorldPoint. but it comes up as an error
mousePos = Input.mousePosition; //this is already defined at the start
Vector3 placement = new Vector3 (Camera.main.ScreenToWorldPoint(mousePos));
for(int i = 0; i < towers.Count; i ++)
{
if(towers[i].selected == true && Input.GetButtonDown ("Place"))
{
towers[i].selected = false;
GameObject clone = Instantiate(towers[i].towerObject, placement, Quaternion.identity) as GameObject;
}
}
it says
(33,92): error CS1729: The type UnityEngine.Vector3' does not contain a constructor that takes
1' arguments
and
Object reference not set to an instance of an object
Comment
Best Answer
Answer by Scribe · Aug 20, 2014 at 09:01 PM
Vector3 placement = new Vector3 (Camera.main.ScreenToWorldPoint(mousePos));
should be:
Vector3 placement = Camera.main.ScreenToWorldPoint(mousePos);
Scribe
Your answer
Follow this Question
Related Questions
Wrong world point mouse position 1 Answer
How to keep the same position of the object instead of camera 0 Answers
Problem with ScreenToWorldPoint and touches (C#) 2 Answers
Camera.main.ScreenToWorldPoint works within Unity editor, but not in builds 0 Answers
Understanding Unity's coordinate system 3 Answers