- Home /
Question by
Infinite_Gamer · Jun 23, 2014 at 06:43 PM ·
c#gameobjectspawn
(C#)Place GameObject from Mouse
Hello Unity Community. What I am trying to to is place a gameobject if it is less or equal to "X".
Here is my script.
using UnityEngine;
using System.Collections;
public class PlaceObject : MonoBehaviour
{
public GameObject Player;
public GameObject Test;
private Vector3 BuildDis;
void Update ()
{
BuildDis.x = Player.transform.position.x + 10;
if(Input.GetKey(KeyCode.Mouse0))
{
if(Input.mousePosition.x <= BuildDis.x)
{
Vector3 MousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,0.0f));
Instantiate(Test, new Vector3(MousePos.x, MousePos.y, 0.0f), Quaternion.identity);
}
}
}
}
I do not get any errors but it does not work.
Thanks for the help in advanced :D
Comment