Recently, I’ve been developing a small RPG style game for a school project. When pressing play, I received a error that says the name ‘impact’ doesn’t exist in the current text. I’m not the biggest JS or C# coder so I’m not really sure how to fix it, any help would be appreciated.
using UnityEngine;
using System.Collections;
public class Sword : MonoBehaviour {
public Transform impactPrefab;
public LayerMask mask;
public float damage = 25f;
public bool canattack = false;
void OnCollisionEnter(Collision collision)
{
if (canattack)
{
foreach (ContactPoint contact in collision.contacts)
{
if (collision.relativeVelocity.magnitude > .2f)
{
GameObject impactPrefab = Instantiate(impactPrefab, contact.point, Quaternion.FromToRotation(Vector3.up,contact.normal))as GameObject;
impact.transform.localRotation = impact.transform.localRotation * Quaternion.Euler(0,Random.Range(-90,90),0);
collision.gameObject.SendMessage ("Damage", damage,SendMessageOptions.DontRequireReceiver);
}
}
}
}
}