Need Help with scripting problem. I am trying to make a City Building game where the building will randomly destroy if not clicked. The script does change the texture to “txture” and destroy it. The problem now is that the script still doesn’t change/revert to “original.” i Think the problem lies with the Raycast problem. Any solution for this will be helpful. Thanks
var Txture : Texture;
var Original : Texture;
function Start ()
{
InvokeRepeating ("Riot", 1, 1);
}
function Riot() {
var RiotRandom : int = Random.Range(1,100);
if (RiotRandom > 1) {
renderer.material.mainTexture = Txture;
}
InvokeRepeating ("Destroyz", 5, 1);
}
function Destroyz() {
if(Input.GetMouseButtonDown(0)){
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit, 150) &&(hit.transform.tag == "Bd1"))
{
renderer.material.mainTexture = Original;
}
}
else
{
Destroy(gameObject);
}
}
Note: Bd1 is the building tag & I Put this script at the building, not camera