Search Unity

Using the parameters of a method automatically

Discussion in 'Scripting' started by FeastSC2, Aug 20, 2017.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I'm using a state machine that is class based.

    Here's an example of my one of my states:
    Code (CSharp):
    1. public class JumperPatrol : State<EnemyJumperAI>
    2. {
    3.     public static JumperPatrol Instance = new JumperPatrol();
    4.  
    5.     public override void Enter(EnemyJumperAI _c)
    6.     {
    7.         _c.CurrDir = Random.Range(0, 2) == 0 ? Vector2.left : Vector2.right;
    8.     }
    9.  
    10.     public override void Execute(EnemyJumperAI _c)
    11.     {
    12.         _c.ChangeDirectionDependingOnTerrain();
    13.  
    14.         if (_c.FacingTheTarget() && _c.DistanceToTarget() <= _c.DistanceBeforeAttack)
    15.         {
    16.             _c.Fsm.ChangeState(JumperJumpAttack.Instance);
    17.         }
    18.     }
    19.  
    20.     public override void Exit(EnemyJumperAI _c)
    21.     {
    22.     }
    23. }
    As you can see, I constantly have to call the methods from the parameter called "_c", is there a way for me to skip that part where I constantly have to write out _c?

    To explain this in different words: I want to keep the same behaviour as I do right now, I just would like not to have to write _c every time I use something because it makes it harder to understand the code. How can I achieve that?
     
    Last edited: Aug 20, 2017