Player invisable cloak?

In my game I want the enemy(other team) to be able to turn invisable for a short amount of time, with a recharge time. So, how do I achieve this, is there a way to disable mesh render, or should I have it so the mesh for the player moves below the floor?

1 Answer

1

Well, you’re going to be disabling the mesh renderer of the players, and to do that you will need to access the objects (players) with a script. Now I’m not going to make a complete script or anything, but I’m gonna give you an example so you’ll get the idea.

I hope this helps.

var Player : GameObject;

var TimeEnabled : float; //this is the amount of seconds the players will be cloaked

var IsCloaked : boolean = false;

function Update () {

if(Input.GetKeyDown(KeyCode.C)){ //you may use any input here, this is just an example

if(IsCloaked == false){
Cloak();
}

}

}

function Cloak () {

Player.renderer.enabled = false;
IsCloaked = true;
yield WaitForSeconds(TimeEnabled);
Player.renderer.enabled = true;
IsCloaked = false;


}

Thanks, TheRichardGamer, your code works great. Just what I needed

Glad I could help.