- Home /
Problem is outdated
OnTriggerEnter/Stay/Exit Assign/Clear variable
Hello! I'm gonna keep this fast and simple :)
Picture shows the player and 3 trigger boxes. I want to be able to move around a level full of these, when I hit one I want that particular trigger box to become the target for where the player places a marker down, so that where ever the player is standing, the marker is always placed in the middle of the square he's on, even if he's closer to the corner or edge of it.
The space between these triggers is going to be very small, but they have to assign and clear themselfs as the player moves around. I don't want to place a marker on the square I was previously on of course.
Right now this kind of works but only for the first trigger that I enter. It gets assigned to the players "where to create cube (marker) variable" and you can place the marker by clicking on the screen. However, if I move just an inch, the target gets cleared and nothing ever assigns again. At best, I've managed to get it to work so that only that initial target can get re-assigned. But the other ones keep ignoring me.
var createmarkerscript : createmarkerscript;
function Update(){
}
function OnTriggerEnter (collider : Collider) {
if (collider.gameObject.tag == "Player"){
createmarkerscript.place = gameObject;
}
}
function OnTriggerExit (collider : Collider) {
createmarkerscript.place = null;
}
Thats the script that is attatched to the target trigger boxes, that I want to assign to the players target.
var SingleMarker : GameObject;
var place : GameObject;
function Update () {
if(Input.GetMouseButtonDown(0))
var SingleMarker : GameObject = Instantiate(SingleMarker, place.transform.position, place.transform.rotation);
}
This is what is currently on the player. Where "place" is the target where we want to create the marker.
So the problem again (and in short) is:
Want to assign GameObjects to players target using triggers. Only works once if even. Want to clear the target when the player steps of a trigger and onto another one, currently only clears but never re-assigns.
Any ideas? I'm gonna assume I don't want to do this in an Update function as I'm going to have quite a few of these boxes on each level and that would probably be a lot of wasted calculations.
Hope you guys can figure something out! Thanks!!
NEVER $$anonymous$$IND (??) It seems to have solved itself.. for now
I'll leave this question open just a bit longer while I debug it (a day or two). If it breaks down it's best if I just use this topic again.