Alright, hi there; I’ve been working on a script for an ashtray in a sort of ‘use object->thing happens to the ashtray’ type situation. I’ve got four different GameObjects for the ashtray, one of each version: Ashtray with crumbled paper, ashtray with ashes, ashtray with key, and plain old ashtray. It is supposed to change when I press the ‘e’ key. I don’t need a cycle; once it’s hit all of them, it needs to stay at ‘plain old ashtray’.
My problem is thus:
Something in the c# code is not working, and unity keeps telling me this:
[30138-screen+shot+2014-07-31+at+5.52.35+pm.png|30138]
Here’s the full code I’ve got so far:
using UnityEngine;
using System.Collections;
public class AshtrayControlleyThing : MonoBehaviour {
GameObject object1 = Obj("Ashtray-Paper Model");
GameObject object2 = Object("1Ashes Model");
GameObject object3 = Object("2Key Model");
GameObject object4 = Object("3Empty Model");
//[RequireComponent (typeof (GameObject ("Open Lighter")))];
/*[RequireComponent (typeof(BoxCollider))]
receive Input*/
void Update(){
if (Input.GetKey ("e")) {
if (object3) {
Instantiate (object4, object3.transform.position, object3.transform.rotation);
Destroy (object3);
}
if ( object2) {
Instantiate (object3, object2.transform.position, object2.transform.rotation);
Destroy (object2);
}
if ( object1) {
Instantiate (object2, object1.transform.position, object1.transform.rotation);
//remove object1
Destroy (object1);
}
}
}
/*function onKey ("e")(){
[RequireComponent (typeof (GameObject ("Open Lighter")))];
Instantiate(object2,object1.transform.position,object1.transform.rotation);
//remove object1
Destroy(object1);
if (object1=Destroy){
[RequireComponent (typeof (GameObject ("Brush")))];
Instantiate(object3,object2.transform.position,object2.transform.rotation);
//remove object2
Destroy(object2);}
if (object2=Destroy)(object1=Destroy){
Instantiate(object4,object3.transform.position,object3.transform.rotation);
//remove object3
Destroy(object3);}
}*/
}
(The stuff in comments I decided to not pay attention to in the meantime; mostly so I could get the main code working (the switchy part), but if you have any idea how to do this, I need to use a lighter from my inventory to make the ashtray go from crumbled paper ver. to ashes ver., then a brush to go from ashes ver. to key ver., and then pick up the key; but I think that’s a whole new script.)
Thank you!