therealnemis

2D Game

Mar 3rd, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. New Project - 2D
  2.  
  3. Title it accordingly
  4.  
  5. Create folder called Scripts
  6. Create C# Script : Player
  7. Controller2D
  8.  
  9. Create Folder called Materials
  10. Create Material called Player
  11.  
  12. Create a GameObject -> 3DObject -> Quad
  13. Remove mesh collider from quad
  14. rename Quad to player
  15. Change the color of material player, assign it to the player
  16.  
  17. Open up player.cs
  18.  
  19.  
  20. using UnityEngine;
  21. using System.Collections;
  22.  
  23. [RequireComponent (typeof (Controller2D))]
  24. public class Player : MonoBehaviour{
  25.  
  26. Controller2D controller;
  27.  
  28. void Start(){
  29. controller = GetComponent<Controller2D> ();
  30. }
  31.  
  32.  
  33. Go into Controller2D.cs
  34.  
  35. using UnityEngine;
  36. using System.Collections;
  37.  
  38. [RequireComponent (typeof (BoxCollider2D))]
  39. public class Controller2D : MonoBehaviour {
  40. BoxCollider2D collider;
  41.  
  42. void Start(){
  43. collider = GetComponent<BoxCollider2D>();
  44. }
  45. }
  46.  
  47.  
  48. Apply player script to Player
  49.  
  50. in Controller.cs
  51.  
  52. Create a new method
  53.  
  54. struct RaycastOrigins {
  55. public Vector2 topLeft, topRight;
  56. public Vector2 bottomLeft, bottonRight;
  57. }
  58.  
  59. under BoxCollider2D collider;
  60.  
  61. RayCastOrigins raycastOrigins;
  62.  
  63. create another method
  64.  
  65. void UpdateRaycastOrigins(){
  66. Bounds bounds = collider.bounds;
  67. bounds.Expand(skinWidth * -2);
  68.  
  69. raycastOrigins.bottomLeft = new Vector2(bounds.min.x, bounds.min.y);
  70. raycastOrigins.bottomRight = new Vector2(bounds.max.x, bounds.min.y);
  71. raycastOrigins.topLeft = new Vector2(bounds.min.x, bounds.max.y);
  72. raycastOrigins.topRight = new Vector2(bounds.max.x, bounds.max.y);
  73.  
  74. }
  75.  
  76.  
  77. Create a global variable
  78.  
  79. const float skinWidth = .015f;
  80.  
  81. create two public integers
  82.  
  83. public int horizontalRayCount = 4;
  84. public int verticalRayCount = 4;
  85.  
  86. float horizontalRaySpacing;
  87. float verticalRaySpacing;
Add Comment
Please, Sign In to add comment