❔ Easy problem C# Unity
Hello there, im trying on following a tutorial for my game but im stuck. the problem is that i want my npc to go on a particular node only if a door is open and goes back to another previous node if the door is closed. of course i know that this is just a simple question and i can do that by using bools and if statement but actually im very dumb at coding and ive already tryed but without succes and i need help to add this stuff to my preexisting code that i barely understand.
DoorCode https://pastebin.com/7bQuR5yx
NpcCode https://pastebin.com/p6zYY0ef
NpcCodeEditor https://pastebin.com/9AmX5yQR
Pastebin
using System.Collections;using System.Collections.Generic;using Uni...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
using System.Collections;using System.Collections.Generic;using Uni...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
using UnityEngine;using UnityEditor;using System.Collections;using ...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
2 Replies
I also have already the answer to my question but i still have difficulty to do this:
If you want the door to stop the animation, all you need to do is 'expose' the door state to that script. You can do this in a number of ways:
1) Add a reference to the door as a public or [SerializeField] variable. If the state of the door is not public, either make it public in the script or make a public IsOpen() method that returns the state of the door.
2) Create a constraint system that is more versatile using an Interface (or possibly an Abstract class) and child classes that implement the Interface. Since the nodes are all the same script component class, adding a public array of 'constraint's would be more versatile in the future and allow you to stop movement based on other things than just checking a door. Create an Interface class I_NodeConstraint and have the virtual method called something like CheckConstraint(). Create child classes for each type of I_Contraint you with to implement such as: ClosedDoorConstraint, TooEaryInGameConstraint, TimerConstraint. Pretty much anything you want that would need some logic to determine if you are allowed to move to that location. Any object added should have a child class of I_NodeConstraint added to do it and placed in the public list of Node array variable. When deciding to move to a Node, loop through all CheckConstraint() methods on each object in the array, which should perform some logic and return a true or false value based on their internal logic. If they all return 'true' then you can move there. If they return false then don't (or flip it around, whatever makes sense to you).
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.