Advertisement
Guest User

RT wybuch

a guest
Aug 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. Kod 1 do pierwszego pliku:
  2.  
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. public class Defragmentation : MonoBehaviour {
  8.  
  9.     public GameObject effect;
  10.     public Vector3 effectOffset;
  11.     public GameObject trail;
  12.     public int maxTrails;
  13.     public float effectDestroy;
  14.     public float minForce;
  15.     public float maxForce;
  16.     public float radius;
  17.     public float destroyDelay;
  18.  
  19.     void Start(){
  20.         Explode ();
  21.     }
  22.  
  23.     public void Explode (){
  24.         int trailCounter = 0;
  25.             if (effect != null && effectDestroy != null){
  26.                 GameObject ExplosionFX = Instantiate (effect, transform.position + effectOffset, Quaternion.identity) as GameObject;
  27.                 Destroy (ExplosionFX, effectDestroy);
  28.             }
  29.         foreach (Transform t in transform){
  30.         var rb = t.GetComponent<Rigidbody> ();
  31.         if(rb != null){
  32.             rb.AddExplosionForce (Random.Range(minForce, maxForce), transform.position, radius);
  33.         }
  34.         if (trail != null && trailCounter < maxTrails){
  35.             if (Random.Range(1, 3) == 1){
  36.                 GameObject trailFX = Instantiate (trail, t.transform) as GameObject;
  37.                 trailCounter++;
  38.                 Destroy (trailFX, effectDestroy);
  39.             }
  40.         }
  41.         Destroy (t.gameObject, destroyDelay);
  42. }}}
  43.  
  44.  
  45. Kod 2 do drugiego pliku:
  46.  
  47. using System.Collections;
  48. using System.Collections.Generic;
  49. using UnityEngine;
  50.  
  51. public class SpawnDefragmentation : MonoBehaviour {
  52.  
  53.     public GameObject originalObject;
  54.     public GameObject defragmentedObject;
  55.    
  56.     void Update () {
  57.         if (Input.GetMouseButtonDown (0)) {
  58.             SpawnDefragmentedObject ();
  59.         }
  60.     }
  61.  
  62.     public void SpawnDefragmentedObject (){
  63.         Destroy (originalObject);
  64.         GameObject defragmObj = Instantiate (defragmentedObject) as GameObject;
  65.         defragmObj.GetComponent<Defragmentation> ().Explode ();
  66.         }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement