The name 'Impact' doesn't exist in the current text.

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);

                }
                   

            }

               
               

        }
    }
}

You don’t have a variable called impact.

You have a gameObject called impactPrefab on the line above though, maybe you should use impactPrefab. rather than impact.

I tried as WarmedxMints suggested but now it came up with a second error, “Use of local unassigned variable ‘impactPrefab’”, any solution to this?

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;
                    impactPrefab.transform.localRotation = impactPrefab.transform.localRotation * Quaternion.Euler(0,Random.Range(-90,90),0);
                    collision.gameObject.SendMessage ("Damage", damage,SendMessageOptions.DontRequireReceiver);

                }
                   

            }

               
               

        }
    }

it’s because you also have a public transform named impactPrefab. Call the gameobject something else and also make sure you assign something to the public transform.