Search Unity

Prefab Problem

Discussion in 'Prefabs' started by mate_veres, Jan 21, 2020.

  1. mate_veres

    mate_veres

    Joined:
    Oct 19, 2019
    Posts:
    72
    Good evening!

    As you can see in the following script. I am trying to only execute the trigger enter if it is in a certain time. First time when I referenced the sword object from the inspector it went well, but since when I made a prefab from the sword object it can't access the script on the sword.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class collision : MonoBehaviour
    6. {
    7.     public GameObject sword;
    8.  
    9.  
    10.     private void OnTriggerEnter(Collider collider)
    11.     {
    12.         float slashtime = sword.GetComponent<movement>().slashtime;
    13.         Debug.Log(sword );
    14.         Debug.Log(slashtime);
    15.        
    16.         if (collider.tag == "sword" && slashtime+1f > Time.time)
    17.         {
    18.            
    19.             Destroy(gameObject);
    20.         }
    21.     }
    22.  
    23. }
    24.  
    I would be really thankful for any help.