- Home /
Question by
Vioswift · May 08, 2014 at 07:28 AM ·
gameobjectexistsplacing
Unity 3D C# - GameObject Alredy Exists
This is my Code
void Update (){
//display the diestance and direction of where the player is looking
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Debug.DrawRay(ray.origin, ray.direction * MaxDistance, Color.green);
RaycastHit hitLook;
//Distance = hitLook.distance;
if (Physics.Raycast (transform.position, ray.direction * MaxDistance, out hitLook)) {
if (Distance < MaxDistance)
{
if(hitLook.transform.gameObject.tag == "AllowedSelection")
{
if (myCubeLook)
{
//Destroy(myCubeLook.gameObject);
}
else
{
spawnLocation = new Vector3(hitLook.transform.position.x , hitLook.transform.position.y, hitLook.transform.position.z);
Instantiate(myCubeLook, spawnLocation, Quaternion.identity);
}
//myCubeLook.transform.position = hitLook.transform.position;
}
}
}
problem is i can't simply destory the object, What I want to happen is like in minecraft I look at an area and there is like a shadow version of the object I am trying to place.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613144523im_/https://answers.unity.com/themes/thub/images/avi.jpg)