I am working on a object that when it gets hit it blinks.
the blinking part works perfectly but it only occurs one time.
So when the object gets hit a second time it wont blink.
also i use a shield to protect the object and if the shield is activated the blinking event still happens.
Anyone an idea?
Thnx sofar
script:
//Player script
//Inspector Variables
var lives : int = 3;
var playerSpeedVertical : float = 10.0; //speed of the player along the vertical axis
var playerSpeedHorizontal : float = 10.0; //speed of the player along the horizontal axis
var horMin : float = -6.768109; //limits for player movement left
var horMAx : float = 6.719941; //limits for player movement right
var verMin : float = -3.947858; //limits for player movement down
var verMax : float = 5.975672; //limits for player movement up
var projectile : Transform;
var socketProjectile : Transform;
var blinkTime : int = 3;
var shieldMesh : Transform;
var shieldKeyInput : KeyCode;
//Private Variables
private var shieldOn : boolean = false;
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == "astroid")
{
yield WaitForSeconds(0); // The initial delay that you passed to InvokeRepeating
while (blinkTime > 0)
{
blinkTime--;
yield WaitForSeconds(0.2);
renderer.enabled = false;
yield WaitForSeconds(0.2);
renderer.enabled = true;
}
}
}
function Update ()
{
//Store Input Variables
var transV : float = Input.GetAxis ("Vertical") * playerSpeedVertical * Time.deltaTime; //use to store variable for vertical movement
var transH : float = Input.GetAxis ("Horizontal") * playerSpeedHorizontal * Time.deltaTime; //use to store variable for horizontal movement
//Move player based on Input
transform.Translate (transH, transV, 0); //here we use the x move left and right and y to move up and down
//Create out limits for the player world
transform.position.x = Mathf.Clamp(transform.position.x, horMin, horMAx); //set horizontal limits
transform.position.y = Mathf.Clamp(transform.position.y, verMin, verMax); //set vertical limits
//create a bullet
if (Input.GetKeyDown("space"))
{
audio.Play ();
Instantiate (projectile, socketProjectile.position, socketProjectile.rotation);
}
//Create a shield
if(Input.GetKeyDown(shieldKeyInput))
{
if(!shieldOn)
{
var clone = Instantiate (shieldMesh, transform.position, transform.rotation);
clone.transform.parent = gameObject.transform;
shieldOn = true;
}
}
}