Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Organizing and Accessing Avatar Code

Discussion in 'Scripting' started by PatysTy, Feb 12, 2019.

  1. PatysTy

    PatysTy

    Joined:
    Jan 6, 2018
    Posts:
    21
    Hey everyone, this question should be fairly basic for everyone, but I have been having such a hard time wrapping my head around how to use classes with Unity. I am working on a character controller script, however, I want it to be reusable for both human controlled avatars and AI controlled avatars.

    Originally I wrote all of my code in a single C# script attached to my character, but the issue is that I want to separate the code for taking in controller inputs, and the code for actually making the avatar move on screen.

    My script for making the avatar move should only rely on three things. The direction for the avatar to face, the direction to move, and the speed to move at. I would like it so that I could pass these three variables to this script either through a script that gets inputs from a user, or from an AI script. I am confused as the best way to set this up though.

    In essence I need to pass these three variables to my movement script from another script, but the only way I could find to do so would be using a namespace which doesn't seem right to me. I have a feeling this should be straightforward, but can't for the life of me find anything online to help me out with this. If anyone could point me in the correct direction I would really appreciate it.