Ejemplo n.º 1
0
    private void HandlePlayerMovement()
    {
        if (!playerPositionScript)
        {
            playerPositionScript = gameObj.GetComponentInChildren <PlayerPositionScript>();
            if (!playerPositionScript)
            {
                return;
            }
        }

        // Add the latest position to the list if not done before
        newPosition.x = playerPositionScript.playerX;
        newPosition.y = playerPositionScript.playerZ; // playerZ because the PC application is in 3D and Y is up/down

        // Won the game?
        if (newPosition.x == mazeRows - 1 && newPosition.y == mazeColumns - 1)
        {
            winnerText.enabled = true;
        }

        bool pathNeedsUpdate = false;

        if (playerPositionList.Count <= 0)
        {
            lastPosition = newPosition;
            playerPositionList.Add(newPosition);
            pathNeedsUpdate = true;
        }
        else
        {
            lastPosition = playerPositionList[playerPositionList.Count - 1];
            if (lastPosition.x != newPosition.x || lastPosition.y != newPosition.y)
            {
                playerPositionList.Add(newPosition);
                pathNeedsUpdate = true;
            }
        }

        if (pathNeedsUpdate)
        {
            // Update the path inbetween the last and current position
            UpdatePath(lastPosition, newPosition);
        }
    }
Ejemplo n.º 2
0
    /******************************************************
    * MonoBehaviour methods, Awake
    ******************************************************/

    void Awake()
    {
        if (players == null)
        {
            players = new PlayerScript[8];
        }

        players[playerId] = this;

        this.myTransform = transform;
        this.myRigidbody = rigidbody;

        playerPosition = GetComponent <PlayerPositionScript>();
        controls       = GetComponent <PlayerControls>();
        follower       = GetComponent <PathFollowScript>();


        UIMainScript mainUIScript = (UIMainScript)FindObjectOfType(typeof(UIMainScript));

        if (mainUIScript != null)
        {
            follower.isMoving = true;
            IsHuman           = false;
        }

        // register all the multiplier components within this gameobject
        Component[] multiplierComponents = GetComponentsInChildren(typeof(IAccelMultiplier));
        accelMultipliers = new IAccelMultiplier[multiplierComponents.Length];
        for (int i = 0; i < multiplierComponents.Length; i++)
        {
            accelMultipliers[i] = (IAccelMultiplier)multiplierComponents[i];
        }

        motionListeners = new List <IPlayerMotionListener>();
        statListeners   = new List <IStatListener>();

        IsHuman = isHuman;
    }
Ejemplo n.º 3
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            PlayerScript player = other.GetComponent <PlayerScript>();
            player.HP -= HPSettings.RespawnHPCost;

            PlayerPositionScript posScript = other.GetComponent <PlayerPositionScript>();

            Transform previouscheckpoint = posScript.previous;
            other.gameObject.transform.position = new Vector3(previouscheckpoint.position.x, -3, previouscheckpoint.position.z);

            Vector3 currentcheckpoint = new Vector3(posScript.current.position.x, 0, posScript.current.position.z);
            other.gameObject.transform.LookAt(currentcheckpoint);

            PathFollowScript follower = other.GetComponent <PathFollowScript>();
            follower.repathPoints();

            int cameracount = Camera.allCameras.Length;
            for (int i = 0; i < cameracount; i++)
            {
                if (Camera.allCameras[i].GetComponent <CarCamera>() != null)
                {
                    if (Camera.allCameras[i].GetComponent <CarCamera>().targetPlayerId == player.playerId)
                    {
                        Camera.allCameras[i].GetComponent <CarCamera>().isRespawning = false;
                        Camera.allCameras[i].GetComponent <fadeScript>().fadeOut     = false;
                        Debug.Log(Camera.allCameras[i]);
                    }
                }
            }


            if (player.IsHuman == true)
            {
                other.GetComponent <PlayerControls>().isMoving = true;
            }
            else
            {
                follower.isMoving = true;
            }
            if (other.GetComponent <PlayerScript>().playerStatus == 1)
            {
                other.GetComponent <itemEffect>().poisonOff();
                //other.GetComponent<PlayerScript>().playerStatus = 0;
            }
            else if (other.GetComponent <PlayerScript>().playerStatus == 2)
            {
                other.GetComponent <itemEffect>().shieldOff();
                //other.GetComponent<PlayerScript>().playerStatus = 0;
            }

            if (other.GetComponent <itemEffect>().isAutoPilot == true)
            {
                other.GetComponent <itemEffect>().autoPilotOff();
            }
            if (player.itemHeld != 0)
            {
                player.itemHeld = 0;
            }
        }
    }
Ejemplo n.º 4
0
 void Start()
 {
     player         = GetComponent <PlayerScript>();
     playerPosition = GetComponent <PlayerPositionScript>();
 }
Ejemplo n.º 5
0
 void Start()
 {
     player      = GetComponent <PlayerScript>();
     position    = GetComponent <PlayerPositionScript>();
     myRigidbody = rigidbody;
 }