예제 #1
0
    // Update is called once per frame
    private void Update()
    {
        if (!photonView.isMine)
        {
            return;
        }

        // Set controllable for current character
        if (!_controlling && PhotonNetwork.playerName == this.gameObject.GetComponent <Character>().UserName)
        {
            SetControllable();
            _controlling = true;
        }

        // Detect user input of movement
        GameObject joyStick = GameObjectFinder.FindJoyStick();

        if (joyStick == null)
        {
            return;
        }

        // Handle joystick input to move the character
        VirtualJoyStick vjs = joyStick.GetComponent <VirtualJoyStick>();
        Vector3         joyStickMovement = vjs.GetStickPosition();

        if (joyStickMovement != Vector3.zero)
        {
            _rb.AddForce(joyStickMovement * VELOCITY, ForceMode.Acceleration);
        }
        _rb.velocity = Vector3.ClampMagnitude(_rb.velocity, MAX_VELOCITY);

        // Handle joystick input to rotate the character towards
        // the same direction as the joystick
        if (!joyStickMovement.Equals(Vector3.zero))
        {
            Vector3 targetDir = joyStickMovement;
            float   step      = 10;
            Vector3 newDir    = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F);
            _lastRotation      = Quaternion.LookRotation(newDir);
            transform.rotation = _lastRotation;
            photonView.RPC("PlayAnim", PhotonTargets.All, "Move|Move");
        }
        else
        {
            transform.rotation = _lastRotation;
            photonView.RPC("PlayAnim", PhotonTargets.All, "Move|Idle");
        }
    }
예제 #2
0
    // Cast FireBall according to joystick input
    public FireBallController CastFireBall()
    {
        GameObject fb;
        Quaternion destinationAngle;
        Vector3    joyStickMovement =
            GameObjectFinder.FindJoyStick().GetComponent <VirtualJoyStick>().GetStickPosition();
        Vector3 spawnPosition = this.transform.position + joyStickMovement * _fireballSpawnDistance;

        if (joyStickMovement != Vector3.zero)
        {
            destinationAngle = Quaternion.LookRotation(joyStickMovement);
            fb = PhotonNetwork.Instantiate("Prefabs/Fireball", spawnPosition, destinationAngle, 0);
            foreach (var a in OnCastSpellActions)
            {
                a(new FireBall(), fb.transform, -1);
            }
            return(fb.GetComponent <FireBallController>());
        }


        return(null);
    }
예제 #3
0
 // Disable joystick and spell icon
 public static void DisableUi()
 {
     GameObjectFinder.FindJoyStick().SetActive(false);
     GameObjectFinder.FindSpellIcon().SetActive(false);
 }