hi i have been wondering how to use enums in other classes efficiently and after many failures (look below) i have got it set up to work. is it a good way? to keep this short i have cut all unrelated code. note: this is my first time using enums and the switch statement globally, im pretty bad at both but grasp local use perfectly. any insight on this would be much apprieciated. thanks.
here is the way the enum is set up:
using UnityEngine;
using System.Collections;
public enum emotion {
idle, happy, vhappy, angry, vangry, sad, vsad, sleep, hurt, dead
}
public emotion charemote = emotion.idle; // appears in the inspector can be changed and the emotion changes.
public class eyeanim : MonoBehaviour
{
class code...
}
the other class in the parent object attempt 1:
using UnityEngine;
using System;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
[RequireComponent(typeof (Rigidbody))]
public class physicscharcontroller : MonoBehaviour
{
public enum state {
idle, sit, sit2, lay, lay2, gun, carry, hurt, ragdoll, dead
}
public enum emotestate {
idle, happy, vhappy ,angry, vangry, sad, vsad, sleep, hurt
}
public state cstate = state.idle;
public emotestate estate = emotestate.idle; // to change emotion in the emotion script, currently nothing happens when this is changed more later.
void Start(){
eye = GetComponentInChildren<eyeanim>();
}
void Update(){
switch(estate){
case emotestate.idle : eye.charemote = emotion.idle; break; // as a test to change the emotion back from another emotion it errors as of now.
}
}
}
attempt 2:
using UnityEngine;
using System;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
[RequireComponent(typeof (Rigidbody))]
public class physicscharcontroller : MonoBehaviour
{
public enum state {
idle, sit, sit2, lay, lay2, gun, carry, hurt, ragdoll, dead
}
public enum emotestate {
idle, happy, vhappy ,angry, vangry, sad, vsad, sleep, hurt
}
public state cstate = state.idle;
public emotestate estate = emotestate.idle; // to change emotion in the emotion script, currently nothing happens when this is changed more later.
public emotion emot;
void Start(){
eye = GetComponentInChildren<eyeanim>();
}
void Update(){
switch(estate){
case emotestate.idle : eye.charemote = emot.idle; break; // as a test to change the emotion back from another emotion it errors as of now.
}
}
}
attempt 3:
using UnityEngine;
using System;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
[RequireComponent(typeof (Rigidbody))]
public class physicscharcontroller : MonoBehaviour
{
public enum state {
idle, sit, sit2, lay, lay2, gun, carry, hurt, ragdoll, dead
}
public enum emotestate {
idle, happy, vhappy ,angry, vangry, sad, vsad, sleep, hurt
}
public state cstate = state.idle;
public emotestate estate = emotestate.idle; // to change emotion in the emotion script, currently nothing happens when this is changed more later.
public emotion emot;
void Start(){
eye = GetComponentInChildren<eyeanim>();
emot = eye.charemote;
}
void Update(){
eye.charemote = emot; // change this in the inspector and the emotion changes.
/*switch(estate){
case emotestate.idle : eye.charemote = emot.idle; break; //it still errors
}*/
}
}
attempt 4:
using UnityEngine;
using System;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
[RequireComponent(typeof (Rigidbody))]
public class physicscharcontroller : MonoBehaviour
{
public enum state {
idle, sit, sit2, lay, lay2, gun, carry, hurt, ragdoll, dead
}
public enum emotestate {
idle, happy, vhappy ,angry, vangry, sad, vsad, sleep, hurt
}
public state cstate = state.idle;
public emotestate estate = emotestate.idle; // to change emotion in the emotion script, currently nothing happens when this is changed more later.
public emotion emot;
void Start(){
eye = GetComponentInChildren<eyeanim>();
emot = eye.charemote;
}
void Update(){
//eye.charemote = emot; // disable it and...
switch(estate){
case emotestate.idle : eye.charemote = emot.idle; break; // back to square one.
}
}
}
attempt 5:
using UnityEngine;
using System;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
[RequireComponent(typeof (Rigidbody))]
public class physicscharcontroller : MonoBehaviour
{
public enum state {
idle, sit, sit2, lay, lay2, gun, carry, hurt, ragdoll, dead
}
public enum emotestate {
idle, happy, vhappy ,angry, vangry, sad, vsad, sleep, hurt
}
public state cstate = state.idle;
public emotestate estate = emotestate.idle; // to change emotion in the emotion script, currently nothing happens when this is changed more later.
public emotion emot;
void Start(){
eye = GetComponentInChildren<eyeanim>();
emot = eye.charemote;
}
void Update(){
eye.charemote = emot;
switch(estate){
case emotestate.idle : emot = emotion.idle; break; //if changed in the inspector they both work and the emotion switches but it seems a little crude ?
case emotestate.vhappy : emot = emotion.vhappy; break;
}
}
}