Есть скрипт который создаёт декаль, после вызывает метод в другом скрипте(на декале) и там создаётся такая же декаль только с другой стороны. Visual Studio ошибок не видит но когда запускаю и выполняю первый скрипт то пишет - NullReferenceException: Object reference not set to an instance of an object
Сами скрипты:
Первый -
Синтаксис:
Используется csharp
public void _Decal()
{
Vector3 Direction = RaySpawn.TransformDirection(Vector3.forward + new Vector3(Random.Range(-Spread, Spread), Random.Range(-Spread, Spread), 0));
Ray ray = new Ray(RaySpawn.position, Direction);
if (Physics.Raycast(ray, out Hit, 200F))
{
if (Hit.collider)
{
GameObject dec = Instantiate(Decal);
dec.transform.position = Hit.point + Hit.normal * 0.019f;
dec.transform.rotation = Quaternion.LookRotation(-Hit.normal);
dec.transform.SetParent(Hit.transform);
if (Hit.collider.tag == "Sweep")
{
DecalScript._Decal();
}
}
}
}
{
Vector3 Direction = RaySpawn.TransformDirection(Vector3.forward + new Vector3(Random.Range(-Spread, Spread), Random.Range(-Spread, Spread), 0));
Ray ray = new Ray(RaySpawn.position, Direction);
if (Physics.Raycast(ray, out Hit, 200F))
{
if (Hit.collider)
{
GameObject dec = Instantiate(Decal);
dec.transform.position = Hit.point + Hit.normal * 0.019f;
dec.transform.rotation = Quaternion.LookRotation(-Hit.normal);
dec.transform.SetParent(Hit.transform);
if (Hit.collider.tag == "Sweep")
{
DecalScript._Decal();
}
}
}
}
Второй -
Синтаксис:
Используется csharp
public void _Decal()
{
Debug.Log("True");
RaycastHit Hit_2;
Ray ray_decal = new Ray(_Pistol.Hit.point + _Pistol.ray.direction * 5, -gameObject.transform.forward);
if (Physics.Raycast(ray_decal, out Hit_2, 3))
{
GameObject dec_2 = Instantiate(__Decal);
dec_2.transform.position = Hit_2.point + Hit_2.normal * 0.019f;
dec_2.transform.rotation = Quaternion.LookRotation(-Hit_2.normal);
dec_2.transform.SetParent(Hit_2.transform);
}
}
{
Debug.Log("True");
RaycastHit Hit_2;
Ray ray_decal = new Ray(_Pistol.Hit.point + _Pistol.ray.direction * 5, -gameObject.transform.forward);
if (Physics.Raycast(ray_decal, out Hit_2, 3))
{
GameObject dec_2 = Instantiate(__Decal);
dec_2.transform.position = Hit_2.point + Hit_2.normal * 0.019f;
dec_2.transform.rotation = Quaternion.LookRotation(-Hit_2.normal);
dec_2.transform.SetParent(Hit_2.transform);
}
}