万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    UnityScriptはstaticなプロパティができない

    http://wiki.unity3d.com/index.php/AManagerClass#Javascript_-_AManager.js

    UnityScriptだけなぜかプロパティがない・・。
    このようにプロパティ版で書きかえてみた。
    「public static function get instance():AManager {」が具体的な箇所

    #pragma strict
    
    import System.Collections;
    
    public class AManager extends MonoBehaviour
    {
        /// AManager is a singleton.
        /// To avoid having to manually link an instance to every class that needs it, it has a static variable called
        /// instance, so other objects that need to access it can just call:
        ///        AManager.instance.DoSomeThing();
        ///
        private static var s_Instance : AManager;
        public static function get instance():AManager {
            s_Instance =  FindObjectOfType(AManager);
            // This is where the magic happens.
            //  FindObjectOfType(...) returns the first AManager object in the scene.
            if (s_Instance == null)
                Debug.Log ("Could not locate an AManager object. \n You have to have exactly one AManager in the scene.");
    
            return s_Instance;
        }
    
        // Ensure that the instance is destroyed when the game is stopped in the editor.
        function OnApplicationQuit() {
            s_Instance = null;
        }
    }
    


    このようにして、継承し,

    public class Manager extends AManager {
    }
    

    このように使ってみるが、

    private static var _aManaget:AManager;
    _aManaget = Manager.instance;
    

    staticつけてるのにプロパティがstaticだと認識されない・・・

    BCE0020: An instance of type 'AManager' is required to access non static member 'instance'.
    

    ここでも書けないぞって言ってやり取りがある。
    URL:http://forum.unity3d.com/threads/99568-UnityScript-Getter-Setter-Are-they-supposed-to-work