- Home /
This question was
closed Nov 27, 2014 at 05:56 PM by
Avash for the following reason:
Realized after a short while that this this worked as it was supposed to.
How to transfer colllider from OnTriggerEnter to Update
using UnityEngine;
using System.Collections;
public class testtrigger : MonoBehaviour {
Collider lastCollider;
void OnTriggerEnter(Collider other){
lastCollider = other;
Debug.Log (lastCollider);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Debug.Log (lastCollider);
}
}
Line 9 returns a collider butt line 18 returns null. Why?
Comment
Best Answer
Answer by bubzy · Nov 27, 2014 at 05:39 PM
you can try this, it will make sure that lastcollider is not returned from update() unless it has a value.
using UnityEngine;
using System.Collections;
public class testtrigger : MonoBehaviour {
Collider lastCollider;
void OnTriggerEnter(Collider other){
lastCollider = other;
Debug.Log (lastCollider);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(lastCollider != null)
{
Debug.Log (lastCollider);
}
}
}