- Home /
C# Replace objects using if's
using UnityEngine;
using System.Collections;
public class Types : MonoBehaviour {
public Type type = Type.Normal;
public GameObject Big;
public GameObject Bigtag = GameObject.FindGameObjectWithTag("Big");
public GameObject Small;
public GameObject Smalltag = GameObject.FindGameObjectWithTag("Small");
public GameObject Normal;
public GameObject Normaltag = GameObject.FindGameObjectWithTag("Normal");
void OnTriggerEnter(Collider col){
if (col.gameObject.CompareTag("Player")){
if (Type == Type.Big){
Instantiate(NormalPU,BigPU.transform.position,BigPU.transform.rotation);
Destroy(gameObject);
}
if (Type == Type.Small){
Instantiate(NormalPU,SmallPU.transform.position,SmallPU.transform.rotation);
Destroy(gameObject);
}
}
}
public enum Type{
Small,
Big,
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm getting many errors when I start game.
Object is Trigger and it triggers when Player touches it. I have done this with score (score is increasing when player touches). But I can't make:(I have 3 types of objects in prefab:small,normal,big) if type is Big, replace current object(default:normal) with Big one , and so on with type is Small. Also after 10 seconds of replace, replace big/small object back to normal.
Answer by DaveA · Nov 07, 2011 at 06:30 PM
You have delcared the enum as 'Type' and are using what looks like a variable called 'Type' and that's bad. You need to declare a variable of type 'Type' and use that somehow.
Type type = Type.Big
if (type == Type.Big)
etc.
Answer by vozochris_1 · Nov 07, 2011 at 10:37 PM
DaveA, thanks for answer but this didn't help me, I figured it out without any help.