Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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:
    64
    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. AnneSchmidt

    AnneSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    726
  3. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,123
    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. }