using UnityEngine;
using System.Collections;
public class bottleCollector : MonoBehaviour {
public static int _currentBottlesCollected=0;
// Use this for initialization
void Start () {
//do -90 to make it straight
transform.Rotate(-90, 0, 0);
}
// Update is called once per frame
void FixedUpdate () {
float a;
float b;
a = characterScript.hero_z_position;
b = transform.position.z;
//Debug.Log(a);
//transform.Translate(-Vector3.forward * Time.deltaTime);
if(characterScript.hero_z_position>transform.position.z){
Debug.Log("bottle is at the back");
Destroy(gameObject);
}
}
void OnTriggerEnter(Collider other) {
if(other.gameObject.tag == "Player"){
_currentBottlesCollected=_currentBottlesCollected+1;
scoreHandler.currentgameBottlesCollected = _currentBottlesCollected;
// Debug.Log(scoreHandler.currentgameBottlesCollected);
// Debug.Log(".."+_currentBottlesCollected);
Destroy(gameObject);
}}
void OnBecameInvisible() {
Debug.Log("Invisible bottle");
Destroy(gameObject);
}
}
using UnityEngine;
using System.Collections;
public class peopleMovement : MonoBehaviour {
// Use this for initialization
void Start () {
transform.Rotate(0, 180, 0);
Debug.Log("Arrived");
}
// Update is called once per frame
void Update () {
float a;
float b;
a = characterScript.hero_z_position;
b = transform.position.z;
//Debug.Log(b);
//transform.Translate(-Vector3.forward * Time.deltaTime);
if(characterScript.hero_z_position>transform.position.z) {
Debug.Log("i am behind the hero");
Destroy(gameObject);
}
}
void OnBecameInvisible() {
Debug.Log("Invisible man");
Destroy(gameObject);
}
}
I see the Debug.Log message āInvisible bottleā in the console, but i dont see the Debug.Log āInvisible manā. What is wrong ??
Its been 5 hours i am fiddling with it
Just guessing here but reading the docs about OnBecameInvisible it appears to me that there needs to be a renderer component on the same object as the script which implements OnBecameInvisible which isnt the case for your ādrunkā object.
Arterie, thanks, solved it for me too. I use an empty gameobject to parent all my models to but I put my scripts at the top empty gameobject, so no mesh renderer on it. Adding a render component did the trick.
With me, the reason that OnBecameInvisible() didnāt trigger was that while the Game view camera lost vision of the object, the Scene view camera continued to see it. So i had to hide the scene view tab, and leave only the Game view tab visible in the editor.
This was true for me too. I was observing both Scene and Game View side by side and OnBecameInvisible() was not calling. I had to change my Editor layout settings into looking at a single view at a time and it started to work.
Been a long time but speaking for Unity version 2021.3.2f1, I looked away from the object in the scene view, disabled itās shadows, and disabled occlusion culling and the issue was solved.