I’m trying to make a script that moves a certain game objects as long as the player is inside of a certain collider. Here’s the script…
#pragma strict
var UI : GameObject;
var enemy : GameObject;
var fadeTime : float = 0.20763;
var startPosition : float = 78.9;
function Start ()
{
UI.GetComponent.<RectTransform>().anchoredPosition.y = startPosition;
}
function Update ()
{
OnTriggerStay(other: Collider) {
if (other.attachedRigidbody)
}
{
UI.GetComponent.<RectTransform>().anchoredPosition.y -= 0.1 * Time.deltaTime / fadeTime;
}
}
But, I have no idea how to work the OnTrigger Colliders. I pulled that part of the script from the Unity docs adn I have no Idea how to use it. What do I replace? Where do I put everything?
function Update ()
{
OnTriggerStay(other: Collider) {
if (other.attachedRigidbody)
}
{
UI.GetComponent.<RectTransform>().anchoredPosition.y -= 0.1 * Time.deltaTime / fadeTime;
}
}
What is this section of code doing? OnTrigger is a predefined function, If you want to use the UI component in the OnTriggerStay method, do it like this
function Update ()
{
}
function OnTriggerStay(other: Collider) {
if (other.attachedRigidbody)
{
UI.GetComponent.<RectTransform>().anchoredPosition.y -= 0.1 * Time.deltaTime / fadeTime;
}
}
Note that OnTriggerStay calls the method EVERY FRAME you are in the collider, OnTriggerEnter is only the first frame you enter.