i’m trying to set up a script that will turn booleans on or off depending on triggers, in this example i’d like the red block to only be able to move to the edge of the green cubes and no further.
here’s where i’ m mostly failing at the moment:
if i add an OnTriggerExit function to turn the boolean off it’ll not be on even if the space it moves to is of the same type (i suppose because it’s calling Exit on that trigger, which is fair enough), i’ve tried a few things and lots of head-scratching.
i’ve set up 4 colliders surrounding the player piece (which only moves 4 directions) and set them to trigger (or more like tried to) whenever they collide with various tagged objects in hope that it’d be straight forward to set up the movement script to ask if the boolean is on/off to allow movement in that direction (if north collider is colliding with floor, for example, movement north is possible).
here’s one of the many mashed-up scripts i now have:
script
var target: Transform; // tagged "Block"
// var stone: Transform; // tagged "Block"
// var water: Transform;
var onfloor: boolean = false;
var inSpace: boolean = false;
/*function Start(){
if (target == null && GameObject.FindWithTag("Block"))
target = GameObject.FindWithTag("northTrigger").transform;
}*/
function OnTriggerEnter() {
if(target.gameObject.tag == "Block"){
onfloor = false;
collider.isTrigger = true;
print("north is grass");
collider.isTrigger = false;
}
if(target.gameObject.tag != "Block"){
onfloor = false;
collider.isTrigger = true;
print("north is grass");
collider.isTrigger = false;
}
}
/*
function OnTriggerExit() {
if(target.gameObject.tag == "Block"){
// collider.isTrigger = true;
ongrass = true;
print("north is nothing");
// collider.isTrigger = false;
}
}
*/
–
sory about the formatting there, can’t even work out how to get that to print straight here, the “/” are supposed to be commented out sections incase you’d not gathered by now:/.
as you may notice if you’ve bothered to read this far, i’m almost absolutely useless at this stuff:(
no doubt there are myriad better and simpler solutions to this problem, i would like to hear of those that don’t include rigidbodies too if you’re prepared to write them… thanks
also does anyone of a simple line-of-sight checking script i can rip that works[like this but maybe better:?