Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Animatronic : MonoBehaviour
- {
- [System.Serializable]
- public enum Actions
- {
- TPose = 0,
- Stage,
- Standing,
- OutsideCamera,
- OutsideWindow,
- OutsideDoor,
- Kill
- }
- [System.Serializable]
- public struct AnimatronicNodeData
- {
- public Node node;
- public bool weight;
- public Actions action;
- }
- public Node startLocation;
- public Node gameOverLocation;
- [SerializeField]
- Node currentLocation;
- public AnimatronicNodeData[] nodeData;
- public Dictionary<string, AnimatronicNodeData> nodeName2Data;
- Animator animator;
- // Start is called before the first frame update
- void Start()
- {
- nodeName2Data = new Dictionary<string, AnimatronicNodeData>();
- for(int i = 0; i < nodeData.Length; i++)
- {
- nodeName2Data[nodeData[i].node.name] = nodeData[i];
- }
- currentLocation = startLocation;
- this.gameObject.transform.position = currentLocation.gameObject.transform.position;
- this.gameObject.transform.rotation = currentLocation.gameObject.transform.rotation;
- animator = GetComponent<Animator>();
- }
- public void Transition()
- {
- //Grab valid paths
- Node[] outgoingNodes = currentLocation.nodes;
- List<AnimatronicNodeData> validNodes = new List<AnimatronicNodeData>();
- for( int i = 0; i < outgoingNodes.Length; i++)
- {
- AnimatronicNodeData temp = nodeName2Data[outgoingNodes[i].name];
- if(temp.weight == true)
- {
- validNodes.Add(temp);
- }
- }
- if (validNodes.Count > 0)
- {
- int travelToIndex = Random.Range(0, validNodes.Count);
- currentLocation = validNodes[travelToIndex].node;
- this.gameObject.transform.position = currentLocation.gameObject.transform.position;
- this.gameObject.transform.rotation = currentLocation.gameObject.transform.rotation;
- //Set animation state of character
- animator.SetInteger("State", (int)validNodes[travelToIndex].action);
- if(currentLocation.name == gameOverLocation.name)
- {
- GameManager.Instance.GameOver = true;
- }
- }
- // set state
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement