Advertisement
renderbydavid

interact

Oct 29th, 2019
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Interactable : MonoBehaviour
  6. {
  7.     public string Interact;
  8.     //public GameObject ItemToDisable;
  9.     public Sprite MyIndicator;
  10.     public AudioSource ItemCollectSound;
  11.     public void CollectCandy()
  12.     {
  13.         GetComponent<ParticleSystem>().Play();
  14.         GetComponent<BoxCollider>().enabled = false;
  15.         transform.tag = "Untagged";
  16.         ItemCollectSound.Play();
  17.         GetComponent<Rigidbody>().isKinematic = true;
  18.         GetComponent<MeshRenderer>().enabled = false;
  19.         GameObject.Find("PlayerCntrl").GetComponent<Health>().AddHealth(.3f);
  20.         StartCoroutine("Despawn");
  21.     }
  22.  
  23.     public IEnumerator Despawn()
  24.     {
  25.         while (true)
  26.         {
  27.             yield return new WaitForSeconds(2f);
  28.  
  29.             gameObject.SetActive(false);
  30.             yield break;
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement