Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BOO 1.56 KB | None | 0 0
  1. import UnityEngine
  2.  
  3. class asteroidSetup (MonoBehaviour):
  4.     public motionScale = 5.0
  5.     public health = 100
  6.     public poofEffect as ParticleEmitter
  7.     public tier = 2
  8.     private mySphere as SphereCollider
  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.         if (health <= 0):
  15.             Instantiate(poofEffect, transform.position, Quaternion.identity)
  16.             if tier > 0:
  17.                 mySphere = GetComponent[of SphereCollider]()
  18.                 child1 = Instantiate(gameObject, transform.position + (Random.onUnitSphere * mySphere.radius), Quaternion.identity)
  19.                 child1.transform.localScale = transform.localScale * 0.5
  20.                 child1.rigidbody.mass = rigidbody.mass * 0.5
  21.                 child1Script = GetComponent[of asteroidSetup]()
  22.                 child1Script.tier = tier - 1
  23.                
  24.                 child2 = Instantiate(gameObject, transform.position + (Random.onUnitSphere * mySphere.radius), Quaternion.identity)
  25.                 child2.transform.localScale = transform.localScale * 0.5
  26.                 child2.rigidbody.mass = rigidbody.mass * 0.5
  27.                 child2Script = GetComponent[of asteroidSetup]()
  28.                 child2Script.tier = tier - 1
  29.             Destroy(gameObject)
  30.  
  31.     def OnCollisionEnter(collision as Collision):
  32.         poofEffect.worldVelocity = rigidbody.velocity
  33.         for contact in collision.contacts:
  34.             Instantiate(poofEffect, contact.point, Quaternion.identity)
  35.         Debug.Log(collision.relativeVelocity.magnitude)
  36.         health -= collision.relativeVelocity.magnitude
  37.         Debug.Log(health)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement