Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- /*
- * Some simple code for One Way (cloud) Platforms.
- * USAGE: works with horizontal platforms that only the player will stand on.
- * Platform pivot should be where the player can stand. Player pivot should be at the player's feet.
- * <3 - @x01010111
- */
- public class OneWayPlatform : MonoBehaviour {
- public string playerName = "Player";
- private GameObject player;
- //Find player by name
- void Start () {
- player = GameObject.Find(playerName);
- if (player == null) Debug.LogError("(One Way Platform) Please enter correct player name in Inspector for: " + gameObject.name);
- }
- //Check to see if player is under the platform. Collide only if the player is above the platform.
- void FixedUpdate () {
- if (player != null) {
- if (player.transform.position.y < this.transform.position.y) gameObject.collider2D.enabled = false;
- else gameObject.collider2D.enabled = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement