Advertisement
Guest User

CactusDmg

a guest
May 5th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. private var thisrigid : Rigidbody;
  2. var duration : float = 2.5;
  3. var color0 : Color = Color.red;
  4. var color1 : Color = Color.black;
  5. private var t : float = 0;
  6. private var canDestroy : boolean = false;
  7. var dmgdealt : int = 5;
  8. var ObjWithMat : GameObject;
  9. var Player: GameObject;
  10. var healthScript : PlayerHealth;
  11. var Materials : Material[];
  12. function Start(){
  13. if(Player==null){
  14. Player = GameObject.FindGameObjectWithTag("Player");
  15. healthScript = Player.GetComponent("PlayerHealth");
  16.  
  17. }
  18. thisrigid = GetComponent.<Rigidbody>();
  19. }
  20.  
  21. function Update () {
  22. if(canDestroy){
  23. // set material color
  24. if (t < 1){ // while t below the end limit...
  25. // increment it at the desired rate every update:
  26. t += Time.deltaTime/duration;
  27. }
  28. if (t >=1){
  29. Destroy(this.gameObject);
  30. }
  31. ObjWithMat.GetComponent.<Renderer>().sharedMaterials = Materials;
  32. for(var i = 0; i < Materials.length; i++){
  33. Materials[i].color = Color.Lerp (color0, color1, t);
  34. }
  35. }
  36. }
  37.  
  38. function OnCollisionEnter(hit: Collision){
  39. thisrigid.useGravity = true; //Fall to ground
  40. canDestroy = true;
  41. if(hit.gameObject.tag == "Player"){
  42. Debug.Log("dsaf"); //Change to Hurt Me
  43. healthScript.curHealth -= dmgdealt; //Take dmg from me
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement