iam new to unity.... i like to know...enable and disable a object with a particular time interval.....or let me know how can i highlight an object using script and particle systems
You can achieve this with a function that toggle gameObject.active. I used InvokeRepeating in my implementation since it is repeatedly called regardless if the object is active or not (an inactive object won't have its update called, so you'd have to resort to a helper object).
With this approach it's simple to use. Here is the complete script.
TogglesActive.js
var interval : float = 1.0f;
function Start()
{
InvokeRepeating("Toggle", interval, interval);
}
function Toggle()
{
gameObject.active = !gameObject.active;
}
- Note: If you just want to toggle the renderer, you can change "gameObject.active" to "renderer.enabled". You need to change it on both sides of assignment inside Toggle.
TogglesRenderer.js
var interval : float = 1.0f;
function Start()
{
InvokeRepeating("Toggle", interval, interval);
}
function Toggle()
{
renderer.enabled = !renderer.enabled;
}
- Note: This can be refactored to work on any Behaviour. However since Renderer isn't a Behaviour (it is a Component, which is strange, since Behaviour only expose an extra "enabled" member), you can't use this on a renderer. Use the above script instead in that case.
TogglesBehaviour.js
var toToggle : Behaviour;
var interval : float = 1.0f;
function Start()
{
InvokeRepeating("Toggle", interval, interval);
}
function Toggle()
{
if (!toToggle)
return;
toToggle.enabled = !toToggle.enabled;
}