Search Unity

how to use addreward in non agent files.

Discussion in 'ML-Agents' started by hammer_head, Apr 3, 2020.

  1. hammer_head

    hammer_head

    Joined:
    Nov 4, 2018
    Posts:
    11
    Hi ,

    I have a situation where I want to use AddReward() in "void OnTriggerEnter2D (Collider2D col)" that is part of some other non agent file of same project , how can this be done?

    lets say I have different scripts attached to different game objects which is usually the case and I want to use AddReward() as part of some collision or some other events in those scripts , how can I do it ? I cannot have every game object as agent right.

    I may be difficult to re code the whole project and get it inside agent .

    Thanks
    M ANILKUMAR
     
  2. LexVolkov

    LexVolkov

    Joined:
    Sep 14, 2014
    Posts:
    62
    Code (CSharp):
    1. void OnTriggerEnter2D (Collider2D col)
    2. {
    3.    col.transform.GetComponent<AgentBrain>().AddReward(1);
    4. }
    something like this?
     
  3. hammer_head

    hammer_head

    Joined:
    Nov 4, 2018
    Posts:
    11
    Thanks a Lot , works like charm.

    :):):)