Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private var thisrigid : Rigidbody;
- var duration : float = 2.5;
- var color0 : Color = Color.red;
- var color1 : Color = Color.black;
- private var t : float = 0;
- private var canDestroy : boolean = false;
- var dmgdealt : int = 5;
- var ObjWithMat : GameObject;
- var Player: GameObject;
- var healthScript : PlayerHealth;
- var Materials : Material[];
- function Start(){
- if(Player==null){
- Player = GameObject.FindGameObjectWithTag("Player");
- healthScript = Player.GetComponent("PlayerHealth");
- }
- thisrigid = GetComponent.<Rigidbody>();
- }
- function Update () {
- if(canDestroy){
- // set material color
- if (t < 1){ // while t below the end limit...
- // increment it at the desired rate every update:
- t += Time.deltaTime/duration;
- }
- if (t >=1){
- Destroy(this.gameObject);
- }
- ObjWithMat.GetComponent.<Renderer>().sharedMaterials = Materials;
- for(var i = 0; i < Materials.length; i++){
- Materials[i].color = Color.Lerp (color0, color1, t);
- }
- }
- }
- function OnCollisionEnter(hit: Collision){
- thisrigid.useGravity = true; //Fall to ground
- canDestroy = true;
- if(hit.gameObject.tag == "Player"){
- Debug.Log("dsaf"); //Change to Hurt Me
- healthScript.curHealth -= dmgdealt; //Take dmg from me
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement