Advertisement
Guest User

Untitled

a guest
May 16th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Animatronic : MonoBehaviour
  6. {
  7. [System.Serializable]
  8. public enum Actions
  9. {
  10. TPose = 0,
  11. Stage,
  12. Standing,
  13. OutsideCamera,
  14. OutsideWindow,
  15. OutsideDoor,
  16. Kill
  17. }
  18.  
  19. [System.Serializable]
  20. public struct AnimatronicNodeData
  21. {
  22. public Node node;
  23. public bool weight;
  24. public Actions action;
  25. }
  26.  
  27. public Node startLocation;
  28. public Node gameOverLocation;
  29.  
  30. [SerializeField]
  31. Node currentLocation;
  32.  
  33. public AnimatronicNodeData[] nodeData;
  34. public Dictionary<string, AnimatronicNodeData> nodeName2Data;
  35.  
  36. Animator animator;
  37.  
  38. // Start is called before the first frame update
  39. void Start()
  40. {
  41. nodeName2Data = new Dictionary<string, AnimatronicNodeData>();
  42.  
  43. for(int i = 0; i < nodeData.Length; i++)
  44. {
  45. nodeName2Data[nodeData[i].node.name] = nodeData[i];
  46. }
  47.  
  48. currentLocation = startLocation;
  49. this.gameObject.transform.position = currentLocation.gameObject.transform.position;
  50. this.gameObject.transform.rotation = currentLocation.gameObject.transform.rotation;
  51.  
  52. animator = GetComponent<Animator>();
  53. }
  54.  
  55. public void Transition()
  56. {
  57. //Grab valid paths
  58. Node[] outgoingNodes = currentLocation.nodes;
  59.  
  60. List<AnimatronicNodeData> validNodes = new List<AnimatronicNodeData>();
  61.  
  62. for( int i = 0; i < outgoingNodes.Length; i++)
  63. {
  64. AnimatronicNodeData temp = nodeName2Data[outgoingNodes[i].name];
  65. if(temp.weight == true)
  66. {
  67. validNodes.Add(temp);
  68. }
  69. }
  70.  
  71. if (validNodes.Count > 0)
  72. {
  73. int travelToIndex = Random.Range(0, validNodes.Count);
  74.  
  75. currentLocation = validNodes[travelToIndex].node;
  76.  
  77. this.gameObject.transform.position = currentLocation.gameObject.transform.position;
  78. this.gameObject.transform.rotation = currentLocation.gameObject.transform.rotation;
  79.  
  80. //Set animation state of character
  81. animator.SetInteger("State", (int)validNodes[travelToIndex].action);
  82.  
  83. if(currentLocation.name == gameOverLocation.name)
  84. {
  85. GameManager.Instance.GameOver = true;
  86. }
  87. }
  88. // set state
  89. }
  90.  
  91. // Update is called once per frame
  92. void Update()
  93. {
  94.  
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement