Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Acessing class variable through a "child" class

Discussion in 'Scripting' started by Zyrcox, Dec 4, 2014.

  1. Zyrcox

    Zyrcox

    Joined:
    Jan 7, 2013
    Posts:
    10
    hi everyone, I'm coding on my spare time, so i'm requesting some help from hard coder guys :p

    the point is I have class01 which contains variables, and another, class02, which is declare in the first one, and I want to acess class01 variable in class02.I have tried declaring public class02, and it works fine but that's not what I want. My code it looks like that in javascript

    public class Class01 {
    var Var01 : int ;
    var Class02Var : Class02;

    function Class01() {
    }

    class Class02 {

    function Class02() {
    }

    function InitVar01() {
    Var01 = 999;
    }​
    }​
    }

    As you see, I want to change class01 var01 from a class02 function, so is there a way to access a "parent class" variable ?
     
    Last edited: Dec 4, 2014
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
  3. Zyrcox

    Zyrcox

    Joined:
    Jan 7, 2013
    Posts:
    10
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Unity's "JavaScript" is just C# with fewer features.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
  6. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    /facepalm
    No
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    On a conceptual level, yes, it kind of is. Most of the concepts of C# apply equally to Unityscript. Jessy's link is perfectly valid and should not be dismissed just because it's talking about C#, since the answer is the same for Unityscript. All information about classes, types, etc. is exactly the same for C# and Unityscript, and different from Java or Javascript.

    --Eric
     
    ZO5KmUG6R likes this.