Changing the state of the character via a trigger

Hi all,
I am working on a project that involves the character changing his state when stood on a trigger. There are four states:

  • None/Neutral
  • Air
  • Fire
  • Water

Upon standing on a trigger with the specific tag, the player will shift into a different state, and on pressing the left-mouse button, will instantiate a different particle/rigidbody.

I am, however, not very successful, and I need immediate assistance, as I am not as good in programming as the majority in the forums. This script is in C#.

using UnityEngine;
using System.Collections;

public class State : MonoBehaviour {
	
	public GameObject particleNone;
	public GameObject particleAir;
	public GameObject particleFire;
	public GameObject particleWater;
	
	private int setStateNone;
	private int setStateAir;
	private int setStateFire;
	private int setStateWater;
	
	void OnTriggerEnter(Collider other) {
		if(other.gameObject.tag == "NonePower") {
			setStateNone();
		}
		
		if(other.gameObject.tag == "AirPower") {
			setStateAir();
		}
		
		if(other.gameObject.tag == "FirePower") {
			setStateFire();
		}
		
		if(other.gameObject.tag == "WaterPower") {
			setStateWater();
		}
	}
	public void Main() {
		state typeofstate = state.None;
		
		
			if(setStateNone) {
				if(Input.GetMouseButton(0)) {
					Instantiate(particleNone);
			}
				if(particleNone == null) {
					Debug.Log("THERE IS NO PARTICLE FOR *NONE*");
			}
		}

			if(setStateAir) {
				if(Input.GetMouseButton(0)) {
					Instantiate(particleAir);
			}
				if(particleAir == null) {
					Debug.Log("THERE IS NO PARTICLE FOR *AIR*");
			}
		}

			if(setStateFire) {
				if(Input.GetMouseButton(0)) {
					Instantiate(particleFire);
			}
				if(particleFire == null) {
					Debug.Log("THERE IS NO PARTICLE FOR *FIRE*");
			}
		}

			if(setStateWater) {
				if(Input.GetMouseButton(0)) {
					Instantiate(particleWater);
			}
				if(particleWater == null) {
					Debug.Log("THERE IS NO PARTICLE FOR *WATER*");
			}
		}
}
	
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
		
	
	public enum state {
		None,
		Fire,
		Water,
		Air
	}
}

You should place the code in Update instead of Main - Main isn’t defined in Unity scripts, and will do nothing unless you call it explicitly. Use GetMouseButtonDown instead of GetMouseButton, or a new particle will be instantiated every frame while the button is pressed.

  using UnityEngine;
  using System.Collections;
 
  public class State : MonoBehaviour {
 
    public GameObject particleNone;
    public GameObject particleAir;
    public GameObject particleFire;
    public GameObject particleWater;
 
    public enum state {
       None,
       Fire,
       Water,
       Air
    }

    private state curState = state.None; // assume None initially
 
    void OnTriggerEnter(Collider other) {
      switch (other.tag){
        case "AirPower":
          curState = state.Air;
          break;
        case "FirePower":
          curState = state.Fire;
          break;
        case "WaterPower":
          curState = state.Water;
          break;
        case "NonePower":
          curState = state.None;
          break;
      }
    }

    void Update() {
      // use GetMouseButtonDown to avoid instantiating tons
      // of particles while the mouse button is pressed:
      if(Input.GetMouseButtonDown(0)){
        // calculate position and rotation to instantiate particles
        // this code just do it at the object's position/rotation
        Vector3 pos = transform.position;
        Quaternion rot = transform.rotation;
        switch (curState)
          case state.Air:
            if (particleAir){
              Instantiate(particleAir, pos, rot);
            } else {
              Debug.Log("THERE IS NO PARTICLE FOR *AIR*");
            }
            break;
          case state.Fire:
            if (particleFire){
              Instantiate(particleFire, pos, rot);
            } else {
              Debug.Log("THERE IS NO PARTICLE FOR *FIRE*");
            }
            break;
          case state.Water:
            if (particleWater){
              Instantiate(particleWater, pos, rot);
            } else {
              Debug.Log("THERE IS NO PARTICLE FOR *WATER*");
            }
            break;
          case state.None:
            if (particleNone){
              Instantiate(particleNone, pos, rot);
            } else {
              Debug.Log("THERE IS NO PARTICLE FOR *NONE*");
            }
            break;
        }
      }
    }
  }