Hello,
I have a GUI click and drag - basically, you can click on a GUI button of, say a turret and a turret prefab is initiated on the mouse position and you can drag it onto the scene somewhere - the problem is, is when I drag it around the scene, its already active - in other words, its shooting the enemy.
I want it to be active when the user clicks (places the turret) - so is there a way to deactivate all the scripts on that particular prefab, and then activate it when the user clicks?
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
var layerMask = 1 << 8;
if (chooseLocation) {
layerMask = ~layerMask;
Physics.Raycast (ray, hit, 500, layerMask);
currentObj.Translate((Vector3(hit.point.x, currentObj.position.y, hit.point.z) - currentObj.position) * Time.deltaTime *followSpeed);
}
if (Input.GetButtonDown("Fire1")){ //Input.GetMouseButton(0)
chooseLocation = false;
}
// Cancel Selection \\
if(Input.GetButtonDown("Fire2") && currentObj.gameObject){
objLimit[currentSelected] ++;
chooseLocation = false;
Destroy(currentObj.gameObject);
}
}
function OnGUI () {
selGridInt = 0;
if(chooseLocation == false){
if (GUI.Button(Rect(10, 10, 120, 30), objItemNames[selGridInt] + " ("+objLimit[selGridInt]+")") && objLimit[selGridInt] > 0){
currentSelected = selGridInt;
chooseLocation = true;
objLimit[selGridInt] --;
currentObj = Instantiate (objGroup[selGridInt],Vector3(0,0,0),Quaternion.identity);
currentObj.gameObject.GetComponent("BoxCollider");
currentObj.position.y = groundPlane.position.y + 0.5;
}
}
Thanks