Advertisement
TheMagzuz

Array error code

Nov 6th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class WallBounce : MonoBehaviour {
  5.  
  6.     // The player transform
  7.     [SerializeField]
  8.     private Transform playerTransform;
  9.  
  10.     // Is the player touching a wall?
  11.     public bool wall = false;
  12.  
  13.     // The layer that the wall is on. Used for collision
  14.     public LayerMask wallLayer;
  15.  
  16.     // The raduis required to detect a wall collision
  17.     public float range = 10.0f;
  18.  
  19.     // The amount of degrees to rotate when colliding with a wall
  20.     public float collsionRotation = 180.0f;
  21.  
  22.     void Awake() {
  23.         playerTransform = gameObject.transform;
  24.     }
  25.  
  26.     void FixedUpdate()
  27.     {
  28.         // If the car is close to a wall...
  29.         if (Physics.OverlapSphere(transform.position, range, wallLayer)[0] != null)
  30.         {
  31.             // ...set wall to true
  32.             wall = true;
  33.         }
  34.         // If not...
  35.         else {
  36.             // ...set wall to false
  37.             wall = false;
  38.         }
  39.  
  40.         // Rotate the car 45 degrees if it is touching a wall
  41.         if (wall) {
  42.             playerTransform.Rotate(collsionRotation, 0, collsionRotation, Space.Self);
  43.            
  44.         }
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement