- Home /
player on trigger enter dont work?
Hello! I just created a script in which a tank when entering a trigger activates the cannon and the target in the player, but the OnTriggerEnter does not let me put anything, (var Player: (none works). Thanks!
#pragma strict
var Range : BoxCollider;
var EnemyTarget : Transform;
var Canon : Transform;
var Player : CharacterController;
function Start () {
}
function Update () {
if(Player.OnTriggerEnter(Range)){
EnemyTarget.active = true;
Canon.active = true;
}
}
Answer by sSuite · Dec 04, 2018 at 05:11 AM
Hey! The problem is that OnTriggerEnter is a function that gets called when an object enters a trigger collider, and not something that can be tested directly from inside of Update.
You'll want to put something like this in a component on your player object:
void OnTriggerEnter (Collider col) {
// col is the collider that we just hit
if (col == range_collider) {
// we just hit range_collider
// do whatever you want here
}
}
Good luck!
Your answer
Follow this Question
Related Questions
How do I make a button appear when my player enters a trigger? 1 Answer
Why does the money counter resets when I pull different objects trough the trigger? 1 Answer
Trigger implementation 1 Answer
OnTriggerStay with multiple collision parameters 1 Answer
Light animation and Main Menu animation at same time from 1 trigger 0 Answers