示例#1
0
 public void Crouch()
 {
     isCrouching = true;
     // Invoke event
     if (onCrouchChanged != null)
     {
         onCrouchChanged.Invoke(isCrouching);
     }
 }
示例#2
0
        void PerformClimb()
        {
            // Check if:
            if (inputV != 0 &&       // Player is pressing UP or DOWN
                climbObject != null) // Player is in front of a climbable
            {
                bool isAtTop                   = climbObject.IsAtTop(transform.position);
                bool isAtBottom                = climbObject.IsAtBottom(transform.position);
                bool isAtTopAndPressingUp      = isAtTop && inputV > 0;
                bool isAtBottomAndPressingDown = isAtBottom && inputV < 0;

                // Check if the Player is:
                if (!isAtTopAndPressingUp &&      // not trying to climb up
                    !isAtBottomAndPressingDown && // not trying to climb down
                    !isClimbing)                  // not climbing
                {
                    // Start climbing
                    isClimbing = true;

                    // Invoke event
                    if (onClimbChanged != null)
                    {
                        onClimbChanged.Invoke(isClimbing);
                    }
                }

                if (isAtTopAndPressingUp || isAtBottomAndPressingDown)
                {
                    // Stop climbing!
                    StopClimbing();
                }
            }

            // Is the player climbing?
            if (isClimbing &&
                climbObject != null) // Note, if this is null, there's an error
            {
                // Make sure physics is disabled before moving the player
                DisablePhysics();

                // Logic for moving the player up and down climbable
                float   x        = climbObject.GetX();
                Vector3 position = transform.position;
                position.x         = x;
                position.y        += inputV * climbSpeed * Time.deltaTime;
                transform.position = position;
            }
        }
示例#3
0
        void DetectGround()
        {
            // Record a copy of what isGrounded was
            bool wasGrounded = isGrounded;

            // Create a ray going down
            Ray groundRay = new Ray(transform.position, Vector3.down);

            // Set Hit to 2D Raycast
            RaycastHit2D[] hits = Physics2D.RaycastAll(groundRay.origin, groundRay.direction, rayDistance);
            foreach (var hit in hits)
            {
                if (CheckGround(hit))
                {
                    // We found the ground! So exit the function
                    break;
                }

                // If hit collider is not null
                // Reset currentJump
            }
            // Check if:
            if (wasGrounded != isGrounded && // IsGrounded has changed since before the detection AND
                onGroundedChanged != null)   // Something is subscribed to this event
            {
                // Run all the things subscribed to event and give it "isGrounded" value
                onGroundedChanged.Invoke(isGrounded);
            }
        }
示例#4
0
        public void TattooGun()
        {
            // Gun logic

            // Invoke event
            if (onShoot != null)
            {
                onShoot.Invoke(isShooting);
            }
        }
示例#5
0
        public void Punch()
        {
            bool wasPunching = isPunching;

            // Perform punch logic


            // Invoke event
            if (onPunch != null && wasPunching != isPunching)
            {
                onPunch.Invoke(isPunching);
            }
        }
示例#6
0
        bool CheckGround(RaycastHit2D hit)
        {
            // Check if:
            if (hit.collider != null &&          // If hit something AND
                hit.collider.name != name &&     // It didn't hit myself AND
                hit.collider.isTrigger == false) // It didn't hit a trigger
            {
                // Reset the jump count
                currentJump = 0;

                // Is grounded!
                isGrounded = true;

                // Set ground normal now that we're grounded
                groundNormal = -hit.normal;

                // Record 'isOnSlope' value
                bool wasOnSlope = isOnSlope;

                // Check if we're on a slope!
                isOnSlope = CheckSlope(hit);

                // Has the 'isOnSlope' value changed?
                if (wasOnSlope != isOnSlope)
                {
                    // Invoke event
                    if (onSlopeChanged != null)
                    {
                        onSlopeChanged.Invoke(isOnSlope);
                    }
                }

                // We have found our ground so exit the function
                // (No need to check any more hits)
                return(true);
            }

            else
            {
                // We are no longer grounded
                isGrounded = false;
            }

            // Haven't found the ground (so keep looking)
            return(false);
        }
        void DetectGround()
        {
            // Record a copy of what isGrounded was
            bool wasGrounded = isGrounded;

            #region Ground Detection Logic
            // Create a ray going down
            Ray groundRay = new Ray(transform.position, Vector3.down);
            // Set Hit to 2D Raycast
            RaycastHit2D[] hits = Physics2D.RaycastAll(groundRay.origin, groundRay.direction, rayDistance);
            foreach (var hit in hits)
            {
                // Detect if on a slope
                if (Mathf.Abs(hit.normal.x) > 0.1f)
                {
                    // Set gravity to zero
                    rigid.gravityScale = 0;
                }
                else
                {
                    // Set gravity to one
                    rigid.gravityScale = 1;
                }

                if (CheckGround(hit))
                {
                    // We found the ground! So exit the loop
                    break;
                }

                // If hit collider is not null
                // Reset currentJump
            }
            #endregion

            // Check if:
            if (wasGrounded != isGrounded && // IsGrounded has changed since before the detection AND
                onGroundedChanged != null)   // Something is subscribed to this event
            {
                // Run all the things subscribed to event and give it "isGrounded" value
                onGroundedChanged.Invoke(isGrounded);
            }
        }
示例#8
0
 public void Init()
 {
     if (Value.GetType() == typeof(string))
     {
         StringCallback?.Invoke(GetString());
     }
     else if (Value.GetType() == typeof(bool))
     {
         BoolCallback?.Invoke((bool)Value);
     }
     else if (Value.GetType() == typeof(int))
     {
         IntCallback?.Invoke((int)Value);
     }
     else if (Value.GetType() == typeof(float))
     {
         FloatCallback?.Invoke((float)Value);
     }
 }
示例#9
0
 public void Set(bool value)
 {
     SetValue(value);
     BoolCallback?.Invoke(value);
     Save();
 }