- Home /
destroying instructions sequence
Im basically trying to make a script where if you enter this trigger, tip1 pops up automatically. and then if you press the button "Tips" on the keyboard, it will destroy tips1 and instantiate tips 2 in its place. however this wont work, yet im given absolutely no error. help?
private var tips1 : GUITexture;
var tipsPREFAB : GUITexture;
private var tips2 : GUITexture;
var tips2PREFAB : GUITexture;
private var tips3 : GUITexture;
var tips3PREFAB : GUITexture;
function InstructionsIntro () {
tips1 = Instantiate(tipsPREFAB, Vector3(.5, .5, 0), Quaternion.identity);
if(Input.GetButtonDown("Tips") && tips1)
{
Destroy(tips1);
tips2 = Instantiate(tips2PREFAB, Vector3(.5, .5, 0), Quaternion.identity);
}
}
function OnTriggerEnter (player : Collider) {
if(player.gameObject.name == "BlueMan")
{
InstructionsIntro();
}
}
Answer by kaleetos · Jul 18, 2011 at 07:52 PM
I believe you are using Input.GetButtonDown incorrectly. The argument for Input.GetButtonDown should be the name of the input button, not the name of the object being clicked on. By default left click is named "Fire1". I think what you might be looking for is the OnMouseDown() function; however this function has to be attached to the actual object being clicked. You could perhaps try attaching an OnMouseDown() function which calls a function (defined by you) that is attached to the player. This function would handle destroying the prefab and instantiating the next prefab in line. In Pseudo code:
The prefab Script
function OnMouseDown(){
player.SendMessage("NextTip");
}
The Player Script
var tips : GameObject[];
private var i : int = 0;
function NextTip(){
Destroy(tips[i]);
Instantiate(tips[i+1]);
i += 1;
}