private void RayCasting(Ray ray )
{
RaycastHit hit;
if(Physics.Raycast(ray, out hit,weaponRange, playerMask))
{
GameObject particle = null;
if (hit.transform.GetComponent<Brick>()) particle = Instantiate(impacts.brick, hit.point, Quaternion.LookRotation(hit.normal));
if (hit.transform.GetComponent<Dirt>()) particle = Instantiate(impacts.dirt, hit.point, Quaternion.LookRotation(hit.normal));
if (hit.transform.GetComponent<Rock>()) particle = Instantiate(impacts.rock, hit.point, Quaternion.LookRotation(hit.normal));
if (hit.transform.GetComponent<Glass>()) particle = Instantiate(impacts.glass, hit.point, Quaternion.LookRotation(hit.normal));
if (hit.transform.GetComponent<Water>()) particle = Instantiate(impacts.water, hit.point, Quaternion.LookRotation(hit.normal));
if (hit.transform.GetComponent<Wood>()) particle = Instantiate(impacts.wood, hit.point, Quaternion.LookRotation(hit.normal));
if (hit.transform.GetComponent<Concrete>()) particle = Instantiate(impacts.concrete, hit.point, Quaternion.LookRotation(hit.normal));
if (hit.transform.GetComponent<Metal>()) particle = Instantiate(impacts.metal, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particle, timeToDestroy);
}
else if (hit.collider.CompareTag("Enemy"))
{
IDamagable hitedEnemy = hit.collider.GetComponent<IDamagable>();
hitedEnemy.TakeDamage(damage);
GameObject impact = Instantiate(enemyImpact, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(impact, 5.0f);
}
}
Текст ошибки:
NullReferenceException: Object reference not set to an instance of an object
Weapon.RayCasting (UnityEngine.Ray ray) (at Assets/Scripts/Weapon.cs:358)