So I feel like I'm having an odd problem. I made a script that will allow my object to move forwards after checking that it won't run into anything using Raycasts. I needed to debug so I put multiple debug.log(s) into my script. When I went to remove this particular debug.log (that still remains in the script below), the object no longer moves forwards. Any help is much appreciated!
public float moveSpeed = 3f;
private BoxCollider boxCollider;
public float maxDistance = 3f;
void Start()
{
boxCollider = GetComponent();
}
void Update()
{
moveForwards();
}
void moveForwards()
{
boxCollider.enabled = false;
RaycastHit hit;
Ray detectingRay = new Ray(transform.position, Vector3.forward);
if (Physics.Raycast(detectingRay, out hit, maxDistance))
Debug.Log("After if(Physics.Raycast(detectingRay, out hit, maxDistance))");
{
boxCollider.enabled = true;
if (hit.transform == null)
{
transform.Translate (Vector3.forward * Time.deltaTime, Space.Self);
}
}
}
↧