ExpressionsChanger.cs (2629B)
1 using System; 2 using System.Collections; 3 using System.Collections.Generic; 4 using UnityEngine; 5 6 public class ExpressionsChanger : MonoBehaviour 7 { 8 public Material m_Norm; //Normal expression for this material 9 public Material m_Squint; //Squint expression for this material 10 public Material m_Happy; //Happy expression for this material 11 12 private Animator ExprAnim; 13 14 private GameObject slime; 15 private PlayerMovement playerMovement; 16 17 18 void Start() 19 { 20 ExprAnim = GetComponentInParent<Animator>(); 21 22 slime = transform.root.gameObject; 23 playerMovement = slime.GetComponent<PlayerMovement>(); 24 } 25 26 27 void FixedUpdate() 28 { 29 30 /*if (Input.GetKey("r")) //if r is pressed, run code 31 { 32 ExprAnim.Play("DEATH2"); //play DEATH2 animation 33 34 GetComponent<Renderer>().material = m_Squint; //change material to Squint 35 } 36 if (Input.GetKey("e")) //if e is pressed, run code 37 { 38 GetComponent<Renderer>().material = m_Norm; //change material to Norm(al) 39 } 40 if (Input.GetKey("q")) //if w is pressed, run code 41 { 42 ExprAnim.Play("WIN2"); //play WIN2 animation 43 44 GetComponent<Renderer>().material = m_Happy; //change material to Happy 45 }*/ 46 47 48 49 if (Input.GetButtonDown(playerMovement.emoteOne)) 50 { 51 ExprAnim.Play("WIN2"); //play WIN2 animation 52 53 if (AudioManager.getInstance() != null && !AudioManager.getInstance().Find("baldwin").source.mute) 54 { 55 AudioManager.getInstance().Find("baldwin").source.Stop(); 56 } 57 58 if (playerMovement.Hat != null) { 59 Invoke("AddHatForce", 0.8f); 60 } 61 } 62 63 if (this.ExprAnim.GetCurrentAnimatorStateInfo(0).IsName("WIN2")) //When WIN2 taunt is playing the material is happy 64 { 65 GetComponent<Renderer>().material = m_Happy; //change material to Happy 66 } 67 68 if (this.ExprAnim.GetCurrentAnimatorStateInfo(0).IsName("TAKEDAMAGE")) //When WIN2 taunt is playing the material is happy 69 { 70 GetComponent<Renderer>().material = m_Squint; //change material to Happy 71 } 72 73 if (ExprAnim.GetCurrentAnimatorStateInfo(0).normalizedTime > 1) //if statement where if there is no animation playing it runs 74 { 75 GetComponent<Renderer>().material = m_Norm; //changes the material to normal 76 } 77 } 78 79 private void AddHatForce() 80 { 81 playerMovement.Hat.GetComponent<Rigidbody>().AddTorque(-playerMovement.Hat.transform.up * 100); 82 } 83 84 85 }