SHARE
TWEET

Array error code

TheMagzuz Nov 6th, 2015 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top