Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- New Project - 2D
- Title it accordingly
- Create folder called Scripts
- Create C# Script : Player
- Controller2D
- Create Folder called Materials
- Create Material called Player
- Create a GameObject -> 3DObject -> Quad
- Remove mesh collider from quad
- rename Quad to player
- Change the color of material player, assign it to the player
- Open up player.cs
- using UnityEngine;
- using System.Collections;
- [RequireComponent (typeof (Controller2D))]
- public class Player : MonoBehaviour{
- Controller2D controller;
- void Start(){
- controller = GetComponent<Controller2D> ();
- }
- Go into Controller2D.cs
- using UnityEngine;
- using System.Collections;
- [RequireComponent (typeof (BoxCollider2D))]
- public class Controller2D : MonoBehaviour {
- BoxCollider2D collider;
- void Start(){
- collider = GetComponent<BoxCollider2D>();
- }
- }
- Apply player script to Player
- in Controller.cs
- Create a new method
- struct RaycastOrigins {
- public Vector2 topLeft, topRight;
- public Vector2 bottomLeft, bottonRight;
- }
- under BoxCollider2D collider;
- RayCastOrigins raycastOrigins;
- create another method
- void UpdateRaycastOrigins(){
- Bounds bounds = collider.bounds;
- bounds.Expand(skinWidth * -2);
- raycastOrigins.bottomLeft = new Vector2(bounds.min.x, bounds.min.y);
- raycastOrigins.bottomRight = new Vector2(bounds.max.x, bounds.min.y);
- raycastOrigins.topLeft = new Vector2(bounds.min.x, bounds.max.y);
- raycastOrigins.topRight = new Vector2(bounds.max.x, bounds.max.y);
- }
- Create a global variable
- const float skinWidth = .015f;
- create two public integers
- public int horizontalRayCount = 4;
- public int verticalRayCount = 4;
- float horizontalRaySpacing;
- float verticalRaySpacing;
Add Comment
Please, Sign In to add comment