コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        if (instance != null)
        {
            //There is another instance already present, remove this one
            Destroy(gameObject);
            return;
        }
        //Assign this instance to a static variable so you can access the movement direction directly at MobileJoystick_UI.instance.moveDirection
        instance = this;

        //This function will initialize canvas element along with the joystick button
        GameObject tmpObj = new GameObject("Canvas");

        tmpObj.transform.position = Vector3.zero;
        mainCanvas              = tmpObj.AddComponent <Canvas>();
        mainCanvas.renderMode   = RenderMode.ScreenSpaceOverlay;
        mainCanvas.pixelPerfect = true;

        //Add Canvas Scaler component
        CanvasScaler canvasScaled = tmpObj.AddComponent <CanvasScaler>();

        canvasScaled.scaleFactor            = 1;
        canvasScaled.referencePixelsPerUnit = 100;

        //Add Graphic Raycaster element
        tmpObj.AddComponent <GraphicRaycaster>();

        //Setup navigation background
        GameObject cntrlTmpObj = new GameObject("Movement Circle");

        cntrlTmpObj.transform.position    = Vector3.zero;
        cntrlTmpObj.transform.parent      = tmpObj.transform;
        moveTouch.backgroundCircle        = cntrlTmpObj.AddComponent <Image>();
        moveTouch.backgroundCircle.sprite = navigationCircle;
        moveTouch.backgroundCircle.rectTransform.anchorMin = new Vector2(0, 0);
        moveTouch.backgroundCircle.rectTransform.anchorMax = new Vector2(0, 0);
        moveTouch.backgroundCircle.rectTransform.sizeDelta = new Vector2(circleSize, circleSize);
        moveTouch.backgroundCircle.rectTransform.pivot     = new Vector2(0, 0);
        moveTouch.backgroundCircle.rectTransform.position  = new Vector3(marginLeft, marginBottom, 0);

        //Navigation button
        cntrlTmpObj = new GameObject("Movement Button");
        cntrlTmpObj.transform.position = Vector3.zero;
        cntrlTmpObj.transform.parent   = tmpObj.transform;
        moveTouch.mainButton           = cntrlTmpObj.AddComponent <Image>();
        moveTouch.mainButton.sprite    = navigationButton;
        moveTouch.mainButton.rectTransform.anchorMin = new Vector2(0, 0);
        moveTouch.mainButton.rectTransform.anchorMax = new Vector2(0, 0);
        moveTouch.mainButton.rectTransform.sizeDelta = new Vector2(buttonSize, buttonSize);
        moveTouch.mainButton.rectTransform.pivot     = new Vector2(0, 0);
        moveTouch.mainButton.rectTransform.position  = new Vector3(marginLeft + (circleSize - buttonSize) / 2, marginBottom + (circleSize - buttonSize) / 2, 0);

        //Save the default location of the joystick button to be used later for input detection
        moveTouch.defaultArea = new Rect(moveTouch.mainButton.rectTransform.position.x,
                                         moveTouch.mainButton.rectTransform.position.y,
                                         moveTouch.mainButton.rectTransform.sizeDelta.x,
                                         moveTouch.mainButton.rectTransform.sizeDelta.y);
    }
コード例 #2
0
    void Start()
    {
        myRB         = GetComponent <Rigidbody>();
        mobilePrefab = GameObject.FindGameObjectWithTag("Joystick");
        mobileJoy    = GameObject.FindGameObjectWithTag("Joystick").GetComponent <MobileJoystick>();
        anim         = GetComponent <Animator>();

        spawner = GameObject.FindGameObjectWithTag("Spawner").GetComponent <SharkSpawning>();
    }
コード例 #3
0

        
コード例 #4
0
 // Start is called before the first frame update
 void Start()
 {
     _mJContr          = GameObject.FindGameObjectWithTag("Joystick").GetComponent <MobileJoystick>();
     _source           = GetComponent <AudioSource>();
     _coinText.text    = "x" + _gold;
     _sRend            = GetComponent <SpriteRenderer>();
     PlayerInstance    = this;
     _camera           = Camera.main.GetComponent <Animator>();
     _rb               = gameObject.GetComponent <Rigidbody2D>();
     _anim             = gameObject.GetComponent <Animator>();
     _hpImg.fillAmount = 1;
 }
コード例 #5
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Debug.Log($"MobileJoystick instance already exists, destroying {gameObject.name}");
         Destroy(this);
     }
     SetActive(false);
 }
コード例 #6
0
    void Start()
    {
        myRB  = GetComponent <Rigidbody>();
        pview = GetComponent <PhotonView>();

        cam          = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraFollow>();
        mobilePrefab = GameObject.FindGameObjectWithTag("Joystick");
        if (mobileJoy != null)
        {
            mobileJoy = GameObject.FindGameObjectWithTag("Joystick").GetComponent <MobileJoystick>();
        }

        minimapCam = GameObject.FindGameObjectWithTag("MinimapCamera").GetComponent <UIManagerOnline>();

        anim = GetComponent <Animator>();

        if (pview.isMine && this.tag == "Player1")
        {
            cam.player1       = this.gameObject;
            minimapCam.player = this.gameObject;
        }

        else if (pview.isMine && this.tag == "Player2")
        {
            cam.player2       = this.gameObject;
            minimapCam.player = this.gameObject;
        }

        else if (pview.isMine && this.tag == "Player3")
        {
            cam.player3       = this.gameObject;
            minimapCam.player = this.gameObject;
        }

        else if (pview.isMine && this.tag == "Player4")
        {
            cam.player4       = this.gameObject;
            minimapCam.player = this.gameObject;
        }

        score = 0;
    }
コード例 #7
0
    private bool lineOfSightForGood = false; // ! This isn't a good name for this variable either.

    private void Awake()
    {
        m_MobileJoystick = FindObjectOfType <MobileJoystick>();
        m_InputHandler   = FindObjectOfType <InputHandler>();
    }
コード例 #8
0
 private void Awake()
 {
     m_MobileJoystick = GameObject.FindObjectOfType <MobileJoystick>();
 }
コード例 #9
0
 private void Awake()
 {
     i = this;
 }