dronkowitz

Ring.cs Script (Sonic Heroes)

Jan 13th, 2021 (edited)
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Ring : MonoBehaviour
  6. {
  7.     GameObject source;
  8.     public AudioClip clip;
  9.     public Collider physicalCollider;
  10.     private bool phased;
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.         source = Resources.Load<GameObject>("Audio Object");
  15.         //Using the Resources folder in the Assests folder you can load up any kind of object
  16.         //With this above line of code. It loads up a GameObject named "Audio Object" From the Resources folder
  17.         //And applies it to the source variable
  18.     }
  19.  
  20.  
  21.  
  22.     private void OnTriggerEnter(Collider other)
  23.     {
  24.         if (phased)
  25.         {
  26.             return;
  27.         }
  28.  
  29.         UltimatePlayerMovement player = other.GetComponent<UltimatePlayerMovement>();
  30.         FollowerNavigation ai = other.GetComponent<FollowerNavigation>();
  31.         if (player || ai)
  32.         {
  33.             GameObject ao = Instantiate(source, transform.position, Quaternion.identity);
  34.             ao.GetComponent<AudioObject>().Setup(clip, transform);
  35.  
  36.             GameInstance.AddRings(other.GetComponentInChildren<CharacterType>().type);
  37.             FindObjectOfType<HUD>().AddPower(1);
  38.             Destroy(gameObject);
  39.         }
  40.  
  41.     }
  42.  
  43.     private void EndPhase()
  44.     {
  45.         phased = false;
  46.     }
  47.  
  48.     public void StartPhase()
  49.     {
  50.         physicalCollider.isTrigger = true;
  51.         phased = true;
  52.     }
  53.  
  54.     private void OnTriggerExit(Collider other)
  55.     {
  56.         if (other.TryGetComponent(out UltimatePlayerMovement player) && phased)
  57.         {
  58.             physicalCollider.isTrigger = false;
  59.             Invoke("EndPhase", 1);
  60.         }
  61.     }
  62. }
Add Comment
Please, Sign In to add comment