- Home /
Trying to Create a Powerup that lasts a certain amount of time
Hello! I'm new to coding, so please bear with me. I'm trying to create code for a powerup that will double the number of points received when other objects are picked up. Here's what I have so far:
#pragma strict
var points : int;
var timer: float = 300; // set duration time in seconds in the Inspector
function Update () {
}
function OnTriggerEnter (col){
timer -= Time.deltaTime;
if (timer > 0)
{
OnTriggerEnter(){
points += (points * 2);
}
}
}
I do have a points mechanic already set up within my PlayerStatus script and the script for the other pickup. But I keep getting this error:
Error BCE0043: Unexpected token: col. (BCE0043) (Assembly-UnityScript)
I've tried replacing "col" with "Collider" and "Collision" and both of them give me this error:
Error BCE0017: The best overload for the method 'doubleScore.OnTriggerEnter(Object)' is not compatible with the argument list '()'. (BCE0017) (Assembly-UnityScript)
I'm at a loss. Anybody have any advice?
Try this:
function OnTriggerEnter(col : Collider)
And to check if something has entered the trigger use this:
if (col.gameObject.name == "Name")
Answer by arklay_corp · Apr 24, 2014 at 01:23 AM
I'm not used to javascript so maybe there are some syntax error, but try:
#pragma strict
var points : int;
var timer: float = 300; // set duration time in seconds in the Inspector
function Update () {
if (timer > 0)
{
timer -= Time.deltaTime;
}
}
function OnTriggerEnter (col: Collider){
if (timer > 0)
{
OnTriggerEnter(){
points += (points * 2);
}
}
}
You will also need to check what hit the collider, as Ant0ny points out