Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Just a super basic scripting question

Discussion in 'General Discussion' started by p_hergott, Oct 12, 2018.

  1. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    110
    Im totalling new to scripting. with that being said, how do I access part of a script, with a different script. such as in the pic. its from an asset (obviously) to which I wish to access part of it to modify with a script that isn't part of the same asset.
     

    Attached Files:

  2. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    1,293
  3. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,187
    It would be something like this:

    Code (CSharp):
    1. using CoverShooter;
    2.  
    3. public class MyScript : MonoBehaviour {
    4.  
    5.     // Click-drag character gameobject into here
    6.     public CharacterHealth charHealth;
    7.  
    8.     void MyFunction()
    9.     {
    10.         charHealth.Health = 0f;
    11.        
    12.         // Or, if there is a damage function inside the CharacterHealth script
    13.         charHealth.Damage(100f);
    14.     }
    15.  
    16. }