Here’s the script :
#pragma strict
var hitPosition : Vector3;
var test : Transform;
var location : boolean = false;
var toDestroy : GameObject;
var destroyNow : boolean = false;
function Update () {
toDestroy = GameObject.FindGameObjectWithTag ("destroy");
if (location == false) {
Debug.Log ("No Location");
gameObject.SendMessage ("PlaceLocation");
}
if (location == true) {
Debug.Log ("Location");
}
if (Input.GetMouseButtonUp(0)) {
destroyNow = true;
}
if (destroyNow == true) {
gameObject.SendMessage ("Destroy");
}
}
function PlaceLocation () {
if (Input.GetMouseButtonDown(0)) {
location = true;
var hit: RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit)) {
hitPosition = hit.point;
Instantiate (test, hitPosition, Quaternion.identity);
}
}
}
function Destroy () {
Destroy (toDestroy);
location = false;
}
So what’s meant to happen when you hold down left click it creates a cube and when you let go it deletes. This works once but the next time it spawns it and deletes it the next frame. What did I do wrong?
Thanks in advance