I’m new to programming. And I’m following the walkerboystudio courseLab 1. And I’m stuck creating a blinking object.
I’ve got this cube has an instantiate for explosion and then blinking that never last =.=
it should be blinking 1’st, then explode and then sets up a new position for the sphere…
Anyone can help me??I don’t seem able to find the errors… :((
Everything is fine until I add in the code for blinking the sphere. arrrggghhh
Seniors!!! HELP ME please…
Here is my update script and the blinking script
function Update ()
{
if (numberOfClicks <=0)
{
Instantiate (explosion,transform.position,transform.rotation); //creates an explosion
var enemyPos = Vector3(Random.Range(-4.5,4.5),Random.Range(-4.5,4.5),0); //new random position for GO
Blink(blinkCount); //blink the sphere
RespawnWaitTime();
if (blinkCount==0)
{transform.position = enemyPos; //relocate the game object to new location
numberOfClicks = storeClicks;
a bit late , is what you can do also but this rejoin other comment, to define a number of time you want blink well you can add a count variable that you set each time you pass in the invoked function and check upon this.
PS>> added a counter …well hope that help
using UnityEngine;
using System.Collections;
public class ToggleRender : MonoBehaviour
{
public float Duration = 3f;
public bool State = true;
public bool Repeat = false;
public int RepeatTime = 0;
int repeatTime = 0;
void OnEnable()
{
if(!renderer)
{
enabled = false;
return;
}
// make sure we dont have negative counter set
RepeatTime = Mathf.Abs(RepeatTime);
// store RepeatTime for reset
repeatTime = RepeatTime;
renderer.enabled = State;
if(!Repeat)
Invoke("Activate", Duration);
else
InvokeRepeating("ActivateRepeating", Duration, Duration);
}
void Activate()
{
renderer.enabled = !State;
enabled = false;
}
void ActivateRepeating()
{
State = !State;
renderer.enabled = State;
if(CheckCount())
{
CancelInvoke();
RepeatTime = repeatTime;
enabled = false;
}
}
bool CheckCount()
{
RepeatTime --;
if(RepeatTime == 0)
return true;
else
return false;
}
}