What I am trying to achieve here is to be able to change the shape and size of an object but only if the object has been selected. My script makes sense to me but does not work. The object can be selected but when I use any of the WASD keys to change its shape nothing happens. Can someone help me out?
var selected = false;
var SelectedGameObject : GameObject;
function Update (){
if(Input.GetMouseButtonDown(0)){
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit, 100.0)){
SelectedGameObject = hit.collider.gameObject;
selected = true;
Change();
Wait(hit.collider.renderer);
}
}
}
function Change (){
if(Input.GetKeyDown(KeyCode.A)){
transform.localScale += Vector3(0.1,0,0);
}
if(Input.GetKeyDown(KeyCode.D)){
transform.localScale += Vector3(-0.1,0,0);
}
if(Input.GetKeyDown(KeyCode.W)){
transform.localScale += Vector3(0,0,0.1);
}
if(Input.GetKeyDown(KeyCode.S)){
transform.localScale += Vector3(0,0,-0.1);
}
}
function Wait(rend : Renderer){
var originalColor = rend.material.color;
rend.material.color = Color.yellow;
yield WaitForSeconds(2);
rend.material.color = originalColor;
}