- Home /
if player = distance, make text visable
The pseudocode pretty much sums up what i'm looking for. I'm not making a game as much as an interactive property plan. I have 3d text with rotators on it, in certain areas. Problem is, i only want them displayed when the "player" is within say 2m of the text. They're currently displayed 24/7, through terrain dips and objects. It's interesting, but not what i need. I'm looking for some ideas, in jscript, if you can.
Answer by save · Jul 10, 2012 at 10:16 PM
Either you could have triggers that activates them or you could check the actual distance.
//Uses a collider on the text object, requires a rigidbody on the player
function OnTriggerEnter () {
renderer.enabled = true;
}
function OnTriggerExit () {
renderer.enabled = false;
}
//Doesn't require any interaction in physics
static var playerT : Transform;
static var showDistance : float = 2.0;
function Start () {
if (playerT==null) playerT = GameObject.FindObjectWithTag("Player").transform;
InvokeRepeating("DistanceToPlayer", 0.0, 0.1);
}
function DistanceToPlayer () {
var sqrLen : float = (playerT.position - transform.position).sqrMagnitude;
if( sqrLen < showDistance*showDistance) {
renderer.enabled = true;
} else {
renderer.enabled = false;
}
}
This code stops the rotators, and the text is still floating around, visable... Edit: got rotators working again, just had to move them. But there's still the constantly visible text... it's just hanging out, mocking me.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
My weapon does no damage? 0 Answers
Assigning variables to GameObjects 2 Answers
'enabled' is not a member of 'Object' 1 Answer
Converting Code Problem 1 Answer