How to make the NavMesh bot that can be able to destroy doors / can destroy some objects, + play sound??? (the script for the bot to be able to walk, search and chase the player is ready).
I used this code and nothing new happened for the bot, but it can work for the player:
using System.Collections;
using UnityEngine;
using UnityEngine.AI;
public class DestroyDoor : MonoBehaviour {
[SerializeField] AudioSource destroySound;
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Door")
{
Destroy(col.gameObject);
destroySound.Play();
}
}
}
One step at a time usually works pretty well.
I’m guessing for doors you will either need to recalculate the navmesh when a door changes, or else use something like a navmesh blocker (I forget their exact names, but there’s plenty of youtube tutorials for doors and navmeshes).
Imphenzia: How Did I Learn To Make Games:
Two steps to tutorials and / or example code:
- do them perfectly, to the letter (zero typos, including punctuation and capitalization)
- stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
Nothing happens? That just sounds like you wrote a bug… and that means… time to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...);
statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
1 Like
my code works for the player, but does not work for the bot
Do your bots have colliders?
1 Like
yes, my bot have collider
I increased the door and bot collider and it worked, thanks!