|
Post by gonzalo on Nov 1, 2021 23:26:47 GMT
Hi, Amazing Product I have been working with it a lot. I would like to get my enemies inactive when are outside of the camera view, I'm using Rooms extensions, but can't get it to work. I thought 2 possibilities on my end: 1) get the Room ID and check if player is in that room: can't get the room ID, I saw other older posts that there is a "get" on ProCamera2DRooms to get current room but I really don't understand how to use it to retrieve the current room ID. 2) probably better and easier way, check if enemy is inside camera's view. can't achieve this using Rooms, I tried "Renderer().isVisible" but it does not take in consideration room size. Could you give me a hint / advice how to achieve this? , I think worst case scenario I would do it by a gameobject in enemy that gives a area when player gets in, but would like to do it in a cleaner way and also get more experience with this Camera. thank you.
|
|
|
Post by Luís Pedro Fonseca on Nov 2, 2021 21:41:57 GMT
Hi gonzalo, the "OnBecameVisible" event should give you what you're looking for. However, notice that if you have the Scene view open (and the object is visible) that won't work properly. You can also use the "Camera.WorldToScreenPoint" which gives a value between 0,1 if inside the camera frustum and above or below that if outside. docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.htmlLet me know if this helps.
|
|
|
Post by gonzalo on Nov 6, 2021 3:15:04 GMT
Hi Luis! Thank you so much for the help, OnBecameVisible and OnBecameInvisible is exactly what I was looking for, I was doing something way more complicated. By adding those built in methods on the game object, I can detect when is inside view or not. Will be around asking more things probably about the camera, it works great so far, thank you!
|
|