Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. 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:
    99
    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:
    1,144
  3. Stardog

    Stardog

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