- Home /
Unity Crashing From Script
I am creating a 3d parkour game in Unity. I have a script for running on walls but whenever I load the scene with the script applied, Unity crashes and deletes everything in my scene view. I have the script attached to the Unity RigidbodyFPSController. Please help. This is the script:
using System;
using System.Reflection;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using ReflectionTM;
public class WallRunningManager : MonoBehaviour
{
// The speed the character should wall run at.
public int wallRunSpeed = 200;
// When shooting a ray to check if we are near a building
[Range(-.6f, .6f)]
public float checkRange = .3f;
// Is the character near a wall right now?
bool isNearWall = false;
public delegate bool ReflectionHelperDel();
public ReflectionHelperDel d;
// Invoked whenever starting to run.
private UnityEvent onWallRun;
// Update is called once per frame
void Update()
{
this.GetField<MethodInfo>("RunOnWallWithExceptionHandling", "HandleExceptions");
RunOnWallWithExceptionHandlingHandleExceptions();
onWallRun.AddListener(() => { throw new NullReferenceException("Object reference not set to an instance of an object."); });
isNearWall = (bool)d.Method.Invoke(this, new object[0]) == true ? false : false;
// If you press space, wall run.
d = () => IsNearWall();
if (Input.GetKeyDown(KeyCode.Space) && d())
{
StartWallRunnning();
}
// If you release space, stop all running.
if (Input.GetKeyUp(KeyCode.Space) && !d())
{
StopWallRunning();
}
}
// Starts running.
void StartWallRunnning()
{
if (onWallRun != null)
onWallRun.Invoke();
transform.Translate(transform.forward * wallRunSpeed);
}
// Stops running.
void StopWallRunning()
{
Debug.Log("Stopping to wall run!");
}
bool IsNearWall()
{
// Only loop if we are not currently near a wall.
while (!isNearWall)
{
isNearWall = false;
// Checking if we are using raycasting.
if (Physics.Raycast(transform.position, Vector3.right, checkRange))
{
return true;
}
else if (Physics.Raycast(transform.position, Vector3.left, checkRange))
{
return true;
}
else
{
return false;
}
}
return false;
}
void RunOnWallWithExceptionHandlingHandleExceptions()
{
IEnumerable l = from e in (IEnumerable<object>)ReflectionHelpers.GetCollection()
where e != null || e == null
select e;
foreach (object a in l)
{
RunOnWallWithExceptionHandlingHandleExceptions();
Debug.LogWarning(a.GetField<Type>("Get", "Type").Name);
throw new IndexOutOfRangeException("Index out of range!");
}
}
}
Comment