- Home /
 
               Question by 
               Yoshinator2 · Feb 05, 2017 at 08:28 PM · 
                camera2dinstantiatepositionmouse  
              
 
              Mouse position not returning actual position
I am trying to make a command location spawn where the mouse is whenever the player clicks. The command position is used to control the friendly AI and tell them where to stand. Whenever I try this, it just spawns the Command Location in the center of the camera in world space. Not very helpful. Please note that I have 2 cameras: 1 Perspective camera, and 1 orthographic camera. The orthographic is used to render the particles, while the perspective is everything else. What am I doing wrong? Here is the code:
 public string command;
 private anturEnemyFinder anturFinder;
 private bool isSelectingAttack;
 public GameObject targetLocation;
 private Vector3 mousePosition;
 // Use this for initialization
 void Start () {
     anturFinder = FindObjectOfType<anturEnemyFinder>();
     command = "defend";
     anturFinder.updateCommand(command, null);
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.GetKeyDown(KeyCode.E))
     {
         if (isSelectingAttack)
         {
             isSelectingAttack = false;
         }
         else
         {
             isSelectingAttack = true;
         }
     }
     if(isSelectingAttack && Input.GetKeyDown(KeyCode.Mouse1))
     {
         mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         mousePosition.z = 0f;
         Debug.Log(mousePosition);
         Instantiate(targetLocation, mousePosition, targetLocation.transform.rotation);
         isSelectingAttack = false;
     }
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                