- Home /
Question by
thealexzava · Jan 01, 2014 at 05:03 PM ·
triggersendmessageactivekeypress
On Trigger Enter, if GetKeyDown "E" add 1 to another script.
var CiboUP_Text : Transform; //Transform
var target : Transform; //Target Script
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "Player") {
CiboUP_Text.active = true;
if(Input.GetKeyDown(KeyCode.E))
{
target = GameObject.FindWithTag("Cibo").transform; //Find Target
target.SendMessage("AddCibo", 1);
CiboUP_Text.active = false;
}
}
}
Comment
Answer by Oribow · Jan 01, 2014 at 07:16 PM
OnTriggerEnter is called only once. My Solution:
var CiboUP_Text : Transform; //Transform
var target : Transform; //Target Script
function OnTriggerEnter (other:Collider)
{
if (other.gameObject.tag == "Player") {
CiboUP_Text.active = true;
}
}
function OnTriggerStay (other : Collider) {
if (other.gameObject.tag == "Player") {
if(Input.GetKeyDown(KeyCode.E))
{
target = GameObject.FindWithTag("Cibo").transform; //Find Target
target.SendMessage("AddCibo", 1);
CiboUP_Text.active = false;
}
}
}
function OnTriggerExit (other : Collider){
CiboUP_Text.active = false;
}
Your answer
Follow this Question
Related Questions
OnTriggerEnter does not make a GameObject active again. 1 Answer
Wait until audio is finished before set active is false 2 Answers
A simple problem with scripts 1 Answer
play animation on keypress if in range 3 Answers
Changing if a GameObject is active, not working for some parts of the script. 0 Answers