I'm super new to c# and I'm making a 3D game in Unity. I have an int that I want to call upon in another script, but the original script that the int is in, lives on a prefab that isn't on my terrain.
Here is my first code that lives on the Prefab.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Radish : MonoBehaviour
{
[SerializeField] AudioSource munchSound;
public int foodCollisions = 0;
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Cow"))
{
munchSound.Play();
foodCollisions++;
}
Destroy(gameObject);
}
}
This is my second code that lives on a GameObject on my terrain.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class FriendMove : MonoBehaviour
{
public Transform Playerpos;
NavMeshAgent agent;
private GameObject radishPrefab;
private Radish radishScript;
void Start()
{
agent = GetComponent<NavMeshAgent>();
radishPrefab = Resources.Load<GameObject>("Radish");
GameObject radishInstance = Instantiate(radishPrefab);
radishScript = radishInstance.GetComponent<Radish>();
}
private void Update()
{
if (radishScript.foodCollisions == 3)
{
agent.destination = Playerpos.position - new Vector3(5, 0, 5);
}
}
}
I've tried a bunch of stuff but I keep getting errors on Unity :( please help!