tanato
tanato
CC#
Created by tanato on 5/16/2023 in #help
❔ Easy problem C# Unity
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).
3 replies