Inheritance: MonoBehaviour, IPointerDownHandler, IPointerUpHandler
コード例 #1
0
    public void StartGame()
    {
        Time.timeScale  = 1;
        hasCollided     = false;
        isCongradulated = false;
        foodEaten       = 0;
        snakeController = transform.GetComponent <SnakeController>();

        snakeController.DestroySnake();
        snakeController.CreateSnake();

        snakeHead      = transform.GetChild(0).gameObject;
        mobileControls = GetComponent <MobileControls>();

        //pool
        CreatePlayField();
        if (pool)
        {
            pool.Reset();
        }
        pool.Create();

        Destroy(blockContainer);

        blockContainer = new GameObject("BlockContainer");

        GenerateFood();
    }
コード例 #2
0
 void Start()
 {
     this.mobi            = GetComponent <MobileControls>();
     this.remainingHealth = this.maxHealth;
     this.rb   = gameObject.GetComponent <Rigidbody2D>();
     this.anim = gameObject.GetComponent <Animator>();
     this.gm   = GameObject.FindGameObjectWithTag("GameMaster").GetComponent <GameMaster>();
 }
コード例 #3
0
 // Start is called before the first frame update
 void Start()
 {
     mainCamera   = GameObject.Find("Main Camera").GetComponent <Camera>();
     homePlanet   = GameObject.Find("planet");
     audioManager = FindObjectOfType <AudioManager>();
     audioManager.Play(mainTheme);
     mobileControls = this.GetComponent <MobileControls>();
 }
コード例 #4
0
    public void OnPointerUp(PointerEventData ped)
    {
        if (ped.pointerId == joy_fID)
        {
            MobileControls.SetJoystickAxis(Vector2.zero);

            bgImg.CrossFadeAlpha(backgroundAlphaUnUsed, 0.2f, false);
            joystickImg.CrossFadeAlpha(joystickAlphaUnUsed, 0.2f, false);
            joystickImg.rectTransform.anchoredPosition = Vector2.zero;

            joyDrag = false; joy_fID = -1; UCE_Tools.joy_tIdx = -1;
        }
    }
コード例 #5
0
ファイル: ControlsManager.cs プロジェクト: K33W1/MOBIGAM-MP
    public void ChangeControls(MobileControls mobileControls)
    {
        CurrentMobileControls = mobileControls;

        if (mobileControls == MobileControls.Joystick)
        {
            UIServiceLocator.Instance.PlayerJoystick.gameObject.SetActive(true);
        }
        else if (mobileControls == MobileControls.Gyroscope)
        {
            UIServiceLocator.Instance.PlayerJoystick.gameObject.SetActive(false);
            DeviceRotation.ResetReferenceRotation();
        }
    }
コード例 #6
0
 public void onInventoryButtonClick()
 {
     if (invUIOpen == false)
     {
         GameObject.Find("Canvas").transform.GetChild(2).GetComponent <InventoryUI>().showInventoryUI();
         invUIOpen = true;
         MobileControls.hideMobileControls(GameObject.Find("Mobile Controls"));
     }
     else if (invUIOpen == true)
     {
         GameObject.Find("Canvas").transform.GetChild(2).GetComponent <InventoryUI>().hideInventoryUI();
         invUIOpen = false;
         MobileControls.showMobileControls(GameObject.Find("Mobile Controls"));
     }
 }
コード例 #7
0
    // Use this for initialization
    void Start()
    {
        //float y = GameObject.Find ("Control Pad").transform.position.x;
        //y += 50;
        //GameObject.Find ("Control Pad").transform.position.Set (GameObject.Find ("Control Pad").transform.position.x, y, 0);
        PlayerEntity playerEntity = gameObject.GetComponent <PlayerEntity> ();

        playerMoveSpeed = playerEntity.getEntitySpeed();
        rb2d            = GetComponent <Rigidbody2D> ();
        anim            = gameObject.GetComponent <Animator> ();
        endPosition     = transform.position;
        anim.SetBool("isIdle", true);
        if (Application.isMobilePlatform)
        {
            isMobile = true;
            MobileControls.showMobileControls(GameObject.Find("Mobile Controls"));
        }
        MobileControls.showMobileControls(GameObject.Find("Mobile Controls"));
    }
コード例 #8
0
    void Awake()
    {
        platformControls = platforms;

        mobileControls = FindObjectOfType <MobileControls>();
        if (IsMobile())
        {
            isMobile = true;
            MobileEvents.OnMobileUse        += OnMobileUse;
            MobileEvents.OnMobileUseUp      += OnMobileUseUp;
            MobileEvents.OnMobileSprintDown += OnMobileSprint;
            MobileEvents.OnMobileSprintUp   += OnMobileSprintUp;
            MobileEvents.OnMobileMenu       += OnMobileMenu;
        }
        else
        {
            CheckForControllers();
            ChangeController(mode);
        }
    }
コード例 #9
0
ファイル: Respawn.cs プロジェクト: madferrretdd/Fall-Gears
    private void Start()
    {
        if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("-WinScene"))
        {
            destroyable.SetActive(true);
            GetComponent <SphereCollider>().enabled = true;

            UIStuff = destroyable.GetComponentInChildren <MobileControls>();
            UIStuff.vehicle.acceleration = 0;
            UIStuff.ReleaseButton("accelerate");
            UIStuff.ReleaseButton("brake");
            UIStuff.ReleaseButton("left");
            UIStuff.ReleaseButton("right");
            UIStuff.enabled = enabled;
        }

        if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("-Race"))
        {
            vehicleModel    = AvatarParent.GetComponentInParent <AvatarSetup>().myCharacter;
            UIStuff         = vehicleModel.GetComponentInChildren <MobileControls>();
            UIStuff.enabled = true;
        }
    }
コード例 #10
0
    private void Update()
    {
        if (joyDrag)
        {
            Vector2 pos = Vector2.zero;
            if (joy_fID != -1)
            {
                int joy_tIdx = -1;
                foreach (Touch touch in Input.touches)
                {
                    joy_tIdx++;
                    if (touch.fingerId == joy_fID)
                    {
                        pos = touch.position - startPos;
                        break;
                    }
                }
                UCE_Tools.joy_tIdx = joy_tIdx;
            }
            else if (Input.mousePresent)
            {
                Vector2 mousePos = Input.mousePosition;
                pos = mousePos - startPos;
            }

            Vector2 virtualAxis = (pos * 0.5f) / movementRange;

            if (virtualAxis.magnitude > 1)
            {
                virtualAxis.Normalize();
            }

            MobileControls.SetJoystickAxis(virtualAxis);
            joystickImg.rectTransform.anchoredPosition = virtualAxis * movementRange;
        }
    }
コード例 #11
0
    // -----------------------------------------------------------------------------------
    // LateUpdate
    // -----------------------------------------------------------------------------------
    private void LateUpdate()
    {
        if (!target)
        {
            return;
        }

        Vector3 targetPos = target.position + offset;

        // rotation and zoom should only happen if not in a UI right now
        if (!Utils.IsCursorOverUserInterface())
        {
            // right mouse rotation if we have a mouse
            if (Input.mousePresent)
            {
                //Down Event (MobileControls)
                if (!camDrag)                                       //Start (MobileControls)
                {
                    camDrag = (Input.GetMouseButtonDown(mouseButton) && !Utils.IsCursorOverUserInterface());
                }

                //Drag Event (Mobile Controls)
                if (Input.GetMouseButton(mouseButton) && camDrag)
                {
                    // initialize the base rotation if not initialized yet.
                    // (only after first mouse click and not in Awake because
                    //  we might rotate the camera inbetween, e.g. during
                    //  character selection. this would cause a sudden jump to
                    //  the original rotation from Awake otherwise.)
                    if (!rotationInitialized)
                    {
                        rotation            = transform.eulerAngles;
                        rotationInitialized = true;
                    }

                    // note: mouse x is for y rotation and vice versa
                    rotation.y        += Input.GetAxis("Mouse X") * rotationSpeed;
                    rotation.x        -= Input.GetAxis("Mouse Y") * rotationSpeed;
                    rotation.x         = Mathf.Clamp(rotation.x, xMinAngle, xMaxAngle);
                    transform.rotation = Quaternion.Euler(rotation.x, rotation.y, 0);
                }

                //Up Event (Mobile Controls)
                if (Input.GetMouseButtonUp(mouseButton))    // (MobileControls)
                {
                    camDrag = false;                        // (MobileControls)
                }
            }
            else
            {
#if _iMMOMOBILECONTROLS
                rotation = MobileControls.Get1FingerRotation(transform, rotation, xMinAngle, xMaxAngle, rotationSpeedTouch);
#else
                // forced 45 degree if there is no mouse to rotate (for mobile)
                transform.rotation = Quaternion.Euler(new Vector3(45, 0, 0));
#endif
            }

            if (rotation != rotOld)
            {
                UCE_Tools.pointerDown = false;
            }
            rotOld = rotation;

            // zoom
            float speed = Input.mousePresent ? zoomSpeedMouse : zoomSpeedTouch;
            float step  = Utils.GetZoomUniversal() * speed;
            distance = Mathf.Clamp(distance - step, minDistance, maxDistance);
        }

        // -- target auto follow
        Vector3 newPos = targetPos - (transform.rotation * Vector3.forward * distance);

        if (autoFollowSpeed > 0)
        {
            transform.position = Vector3.MoveTowards(transform.position, newPos, Time.deltaTime * autoFollowSpeed);
        }
        else
        {
            transform.position = newPos;
        }

        // avoid view blocking (disabled, see comment at the top)
        if (Physics.Linecast(targetPos, transform.position, out RaycastHit hit, viewBlockingLayers))
        {
            // calculate a better distance (with some space between it)
            float d = Vector3.Distance(targetPos, hit.point) - 0.1f;

            // set the final cam position
            transform.position = targetPos - (transform.rotation * Vector3.forward * d);
        }
    }
コード例 #12
0
 void Start()
 {
     this.mobi = GetComponent<MobileControls>();
     this.remainingHealth = this.maxHealth;
     this.rb = gameObject.GetComponent<Rigidbody2D>();
     this.anim = gameObject.GetComponent<Animator>();
     this.gm = GameObject.FindGameObjectWithTag("GameMaster").GetComponent<GameMaster>();
 }
コード例 #13
0
ファイル: Respawn.cs プロジェクト: madferrretdd/Fall-Gears
    public void OnCollisionEnter(Collision other)
    {
        if (other.collider.tag == "Delete")
        {
            coroutine = Explode(0f);
            StartCoroutine(coroutine);
            Instantiate(Bang, transform.position, transform.rotation);

            destroyable.SetActive(false);
            GetComponent <SphereCollider>().enabled = false;

            UIStuff = destroyable.GetComponentInChildren <MobileControls>();
            //ar control = UIStuff.GetComponent<MobileControls>();
            UIStuff.ReleaseButton("accelerate");
            UIStuff.ReleaseButton("brake");
            UIStuff.ReleaseButton("left");
            UIStuff.ReleaseButton("right");
        }

        if (other.collider.tag == "Player")
        {
            Vector3 direction = (transform.position - other.transform.position).normalized;
            other.rigidbody.AddForce(direction * Strength, ForceMode.Impulse);
        }

        if (other.collider.tag == "Win")
        {
            PlayerPrefs.SetInt("PlayerPos", 0);
            authManager = GameObject.FindWithTag("AuthTag").GetComponent <AuthManager>();

            //Player Won The Race add 1 to wins
            authManager.Wins++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Wins").SetValueAsync(authManager.Wins);

            //Player Gets 10 Coins for Winning the race
            authManager.GearTokens = authManager.GearTokens + 10;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("GearTokens").SetValueAsync(authManager.GearTokens);

            //Player Also Completed the Race add 1 to completed
            authManager.Completed++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Completed").SetValueAsync(authManager.Completed);

            //plus 1 gear token for completing the race
            authManager.GearTokens++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("GearTokens").SetValueAsync(authManager.GearTokens);

            //Player Gets 10 Coins for Winning the race
            authManager.Experience = authManager.Experience + 10;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Experience").SetValueAsync(authManager.Experience);

            //Explode on contact with finishline
            Instantiate(Bang, transform.position, transform.rotation);

            //Load Winners scene (position should be fed to GameManager for instantiatingon podeum
            SceneManager.LoadScene(3);
        }

        if (other.collider.tag == "second")
        {
            PlayerPrefs.SetInt("PlayerPos", 1);
            authManager = GameObject.FindWithTag("AuthTag").GetComponent <AuthManager>();

            //Player Gets 10 Coins for Winning the race
            authManager.GearTokens = authManager.GearTokens + 5;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("GearTokens").SetValueAsync(authManager.GearTokens);

            //Player Also Completed the Race add 1 to completed
            authManager.Completed++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Completed").SetValueAsync(authManager.Completed);

            //plus 1 gear token for completing the race
            authManager.GearTokens++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("GearTokens").SetValueAsync(authManager.GearTokens);

            //Player Gets 10 Coins for Winning the race
            authManager.Experience = authManager.Experience + 5;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Experience").SetValueAsync(authManager.Experience);

            //Explode on contact with finishline
            Instantiate(Bang, transform.position, transform.rotation);

            //Load Winners scene (position should be fed to GameManager for instantiatingon podeum
            SceneManager.LoadScene(3);
        }

        if (other.collider.tag == "third")
        {
            PlayerPrefs.SetInt("PlayerPos", 2);
            authManager = GameObject.FindWithTag("AuthTag").GetComponent <AuthManager>();

            //Player Gets 10 Coins for Winning the race
            authManager.GearTokens = authManager.GearTokens + 2;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("GearTokens").SetValueAsync(authManager.GearTokens);

            //Player Also Completed the Race add 1 to completed
            authManager.Completed++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Completed").SetValueAsync(authManager.Completed);

            //plus 1 gear token for completing the race
            authManager.GearTokens++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("GearTokens").SetValueAsync(authManager.GearTokens);

            //Player Gets 10 Coins for Winning the race
            authManager.Experience = authManager.Experience + 2;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Experience").SetValueAsync(authManager.Experience);

            //Explode on contact with finishline
            Instantiate(Bang, transform.position, transform.rotation);

            //Load Winners scene (position should be fed to GameManager for instantiatingon podeum
            SceneManager.LoadScene(3);
        }

        if (other.collider.tag == "fourth")
        {
            PlayerPrefs.SetInt("PlayerPos", 3);
            authManager = GameObject.FindWithTag("AuthTag").GetComponent <AuthManager>();

            //Player Also Completed the Race add 1 to completed
            authManager.Completed++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Completed").SetValueAsync(authManager.Completed);

            //plus 1 gear token for completing the race
            authManager.GearTokens++;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("GearTokens").SetValueAsync(authManager.GearTokens);

            //Player Gets 10 Coins for Winning the race
            authManager.Experience = authManager.Experience + 1;
            authManager.reference.Child("Users").Child(authManager.User.UserId).Child("Experience").SetValueAsync(authManager.Experience);

            //Explode on contact with finishline
            Instantiate(Bang, transform.position, transform.rotation);

            //Load Winners scene (position should be fed to GameManager for instantiatingon podeum
            SceneManager.LoadScene(3);
        }
    }
コード例 #14
0
 void Start()
 {
     pcControls  = GetComponent <PC_Controls>();
     mControls   = GetComponent <MobileControls>();
     gameManager = FindObjectOfType <GameManager>();
 }