// Update is called once per frame.
		void Update () {
			// Check if the player is on a platform.
			platformCollider = Physics2D.OverlapCircle(player.groundCheck.position, player.groundRadius, player.platformLayer);
			
			// If the player is on a platform and not jumping through it...
			if (platformCollider && !currentPlatform && !player.jumpingThrough) {
				// ... set the current platform.
				currentPlatform = platformCollider.transform.parent.transform.parent.gameObject;

				// Set the player's rotation based on the current platform's rotation if rotateOnSlope is enabled.
				if (player.rotateOnSlope) { transform.rotation = currentPlatform.transform.rotation; }

				// Make sure the player is considered grounded.
				player.groundCollider = platformCollider;

				// Get the platform's script.
				platformClass = currentPlatform.GetComponent<Platform>();

				// Shake the camera when on a sinking platform if camera shaking is enabled.
				if (platformClass.PlatformTypeIs(PlatformTypes.Sinking)) {
					platformClass.ShakeCamera();
				}
				
				// If the player is on a moving platform and should use the platform's friction...
				if (platformClass.PlatformTypeIs(PlatformTypes.Moving) && movingPlatform.useFriction) {
					// ... set the friction of the platform.
					platformFriction = platformCollider.gameObject.GetComponent<BoxCollider2D>().sharedMaterial.friction;
					
					// Set the friction of the player.
					playerFriction = GetComponent<BoxCollider2D>().sharedMaterial.friction;
					
					// Set the slowdown based on the friction from both the player and platform.
					slowdown = platformFriction * playerFriction;
				}

				// Let the platform know that the player is standing on it.
				platformClass.SetPlayerOnPlatform(true);
			// Or else...
			} else if (!platformCollider && currentPlatform) {
				// .. let the platform know the player isn't standing on it anymore.
				platformClass.SetPlayerOnPlatform(false);

				// Reset the variables.
				currentPlatform = null;
				platformClass = null;
				unstick = false;
			}

			// Timer for resetting the unstick variable.
			if (unstick) {
				if (unstickTimer > 0) {
					unstickTimer -= Time.deltaTime;
				} else {
					unstick = false;
				}
			}
		}
Esempio n. 2
0
        // Update is called once per frame.
        void Update()
        {
            // Check if the player is on a platform.
            platformCollider = Physics2D.OverlapCircle(player.groundCheck.position, player.groundRadius, player.platformLayer);

            // If the player is on a platform and not jumping through it...
            if (platformCollider && !currentPlatform && !player.jumpingThrough)
            {
                // ... set the current platform.
                currentPlatform = platformCollider.transform.parent.transform.parent.gameObject;

                // Set the player's rotation based on the current platform's rotation if rotateOnSlope is enabled.
                if (player.rotateOnSlope)
                {
                    transform.rotation = currentPlatform.transform.rotation;
                }

                // Make sure the player is considered grounded.
                player.groundCollider = platformCollider;

                // Get the platform's script.
                platformClass = currentPlatform.GetComponent <Platform>();

                // Shake the camera when on a sinking platform if camera shaking is enabled.
                if (platformClass.PlatformTypeIs(PlatformTypes.Sinking))
                {
                    platformClass.ShakeCamera();
                }

                // If the player is on a moving platform and should use the platform's friction...
                if (platformClass.PlatformTypeIs(PlatformTypes.Moving) && movingPlatform.useFriction)
                {
                    // ... set the friction of the platform.
                    platformFriction = platformCollider.gameObject.GetComponent <BoxCollider2D>().sharedMaterial.friction;

                    // Set the friction of the player.
                    playerFriction = GetComponent <BoxCollider2D>().sharedMaterial.friction;

                    // Set the slowdown based on the friction from both the player and platform.
                    slowdown = platformFriction * playerFriction;
                }

                // Let the platform know that the player is standing on it.
                platformClass.SetPlayerOnPlatform(true);
                // Or else...
            }
            else if (!platformCollider && currentPlatform)
            {
                // .. let the platform know the player isn't standing on it anymore.
                platformClass.SetPlayerOnPlatform(false);

                // Reset the variables.
                currentPlatform = null;
                platformClass   = null;
                unstick         = false;
            }

            // Timer for resetting the unstick variable.
            if (unstick)
            {
                if (unstickTimer > 0)
                {
                    unstickTimer -= Time.deltaTime;
                }
                else
                {
                    unstick = false;
                }
            }
        }
Esempio n. 3
0
 // Return if the player is on a platform.
 public bool OnPlatform()
 {
     return(currentPlatform && !platformClass.PlatformTypeIs(PlatformTypes.None));
 }