Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BOO 1.71 KB | None | 0 0
  1. import UnityEngine
  2.  
  3. class asteroidSetup (MonoBehaviour):
  4.     public motionScale = 5
  5.     public health = 100
  6.     public poofEffect as ParticleEmitter
  7.     public tier = 2
  8.     public child as GameObject
  9.     def Start():
  10.         rigidbody.AddForce(Random.value * motionScale, Random.value * motionScale, Random.value * motionScale)
  11.         rigidbody.AddTorque(Random.value * motionScale, Random.value * motionScale, Random.value * motionScale)
  12.    
  13.     def Update():
  14.         Debug.Log("Tier: $tier")
  15.         Debug.Log("Health: $health")
  16.         if (health <= 0):
  17.             Instantiate(poofEffect, transform.position, Quaternion.identity)
  18.             Destroy(gameObject)
  19.             if (tier > 0):
  20.                 child1 = Instantiate(child,
  21.                 transform.position + (Random.onUnitSphere * GetComponent[of SphereCollider]().radius),
  22.                 Quaternion.identity)
  23.                
  24.                 child1.transform.localScale = transform.localScale * 0.5
  25.                 child1.rigidbody.mass = rigidbody.mass * 0.5
  26.                 child1.rigidbody.AddRelativeForce(rigidbody.velocity * motionScale)
  27.                 child1Script = GetComponent[of asteroidSetup]()
  28.                 child1Script.tier = tier - 1
  29.                
  30.                 child2 = Instantiate(child,
  31.                 transform.position + (Random.onUnitSphere * GetComponent[of SphereCollider]().radius),
  32.                 Quaternion.identity)
  33.                
  34.                 child2.transform.localScale = transform.localScale * 0.5
  35.                 child2.rigidbody.mass = rigidbody.mass * 0.5
  36.                 child2.rigidbody.AddRelativeForce(rigidbody.velocity * motionScale)
  37.                 child2Script = GetComponent[of asteroidSetup]()
  38.                 child2Script.tier = tier - 1
  39.  
  40.     def OnCollisionEnter(collision as Collision):
  41.         poofEffect.worldVelocity = rigidbody.velocity
  42.         for contact in collision.contacts:
  43.             Instantiate(poofEffect, contact.point, Quaternion.identity)
  44.         health -= collision.relativeVelocity.magnitude
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement