Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Jump"))
        {
            jumpBuffer = maxJumpBuffer;
        }

        if (nextshotAvailable <= 0 && Input.GetButtonDown("Fire1"))//M1
        {
            nextshotAvailable = shootDelay;
            playerShoot.DoShoot();
        }

        if (unLockedTeleport && nextTeleportAvailable <= 0 && Input.GetButtonDown("Fire3"))//left shift
        {
            nextTeleportAvailable = teleportDelay;
            Vector3 teleport = this.transform.position;
            teleport.x += (directionFacing * teleportDistance);
            RaycastHit hit;
            if (Physics.Raycast(this.transform.position, directionFacing * Vector3.right, out hit, teleportDistance))
            {
                float hitAt = this.transform.position.x + (directionFacing * hit.distance);
                if (directionFacing == -1)
                {
                    if (teleport.x <= hitAt && teleport.x >= hitAt + (directionFacing * hit.collider.bounds.size.x))//land in a wall i think
                    {
                        nextTeleportAvailable = 0;
                    }
                    else
                    {
                        this.transform.position = teleport;
                    }
                }
                else
                {
                    if (teleport.x >= hitAt && teleport.x <= hitAt + (directionFacing * hit.collider.bounds.size.x))//land in a wall i think
                    {
                        nextTeleportAvailable = 0;
                    }
                    else
                    {
                        this.transform.position = teleport;
                    }
                }
            }
            else
            {
                this.transform.position = teleport;
            }
        }
    }