Witam natknąłem się dzisiaj na problem o nazwie NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.Edge.WakeUp () (at <732b665a0eb44a80b9931c01ad63f8b8>:0) i kompletnie nie mam juz pomyslu jak sie go pozbyc
w skyrpcie ponizej chodzi mi o to aby moj przeciwnik ktory wykryje że nie ma ziemi pod nim zawraca w drugi kierunek gdzie ta ziemia jest , w skrypcie mam rowniez juz działajacy wątek robiący to samo tylko że ze scianą oczywiscie mógłbym to zrobic takim samym sposobem jak z tą sciana ale chcialem sie trochę pobawić Physics2D.Raycast() , jestem nowy w srodowisku robienia gier , jakieś dam doswiadczenie z programowaniem mam.
Skypt:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemyContoller : MonoBehaviour
{
public float speed = 5f;
private int isFacingRight;
private Rigidbody2D enemyRB;
public Transform groundpoint;
public float distance;
public bool atTheGround;
public LayerMask Mask;
private Vector2 movement;
void Start()
{
enemyRB=GetComponent<Rigidbody2D>();
isFacingRight = 1;
}
// Update is called once per frame
void Update()
{
rot();
moveEnemy();
}
public void moveEnemy(){
movement.Set(isFacingRight * speed , enemyRB.velocity.y); /* set ustala nowe os x X I Y */
enemyRB.velocity=movement;
transform.Rotate(0f , 0f , 0f);
atTheGround=Physics2D.Raycast(groundpoint.position , Vector3.down ,distance , Mask);
// Debug.Log(atTheGround);
}
public void rot(){
}
public void OnCollisionEnter2D(Collision2D other) {
if(other.gameObject.tag=="wall"){
transform.Rotate(0f , 180f , 0f);
isFacingRight *= -1;
}
}
public void OnDrawGizmos() {
Gizmos.color=Color.red;
Gizmos.DrawWireSphere(groundpoint.position ,distance);
}
}