Advertisement
dronkowitz

PlayerHit.cs

Oct 28th, 2021
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerHit : MonoBehaviour
  6. {
  7.     public AudioClip clip;
  8.     public GameObject ringPrefab;
  9.     GameObject source;
  10.  
  11.     private void Awake()
  12.     {
  13.         source = Resources.Load<GameObject>("Audio Object");
  14.     }
  15.  
  16.     private void Update()
  17.     {
  18.         if (Input.GetKeyDown(KeyCode.P))
  19.         {
  20.             Hit();
  21.         }
  22.     }
  23.  
  24.     public void Hit()
  25.     {
  26.        
  27.         int rings = GameInstance.RemoveRings();
  28.         if (rings > 0)
  29.         {
  30.             GetComponent<UltimatePlayerMovement>().SurrenderControl(Vector2.zero, 1.5f);
  31.             GameObject ao = Instantiate(source, transform.position, Quaternion.identity);
  32.             ao.GetComponent<AudioObject>().Setup(clip, transform);
  33.             for (int i = 0; i < rings; i++)
  34.             {
  35.                 ThrowRing(i);
  36.             }
  37.         }
  38.         else if (rings==0)
  39.         {
  40.             GetComponent<UltimatePlayerMovement>().enabled = false;
  41.         }
  42.     }
  43.  
  44.     public void ThrowRing(int i)
  45.     {
  46.         int force = (i > 10 ? 3 : 12);
  47.  
  48.         float x = Random.Range(-1, 1);
  49.         float z = Random.Range(-1, 1);
  50.  
  51.         GameObject newRing = Instantiate(ringPrefab, transform.position+transform.up, Quaternion.identity);
  52.         newRing.GetComponent<Ring>().StartPhase();
  53.         Rigidbody ringbody = newRing.GetComponent<Rigidbody>();
  54.         ringbody.velocity = new Vector3(x, 1, z) * force;
  55.         ringbody.useGravity = true;
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement