Hello i am facing an error with my script.
‘Enemy’ does not contain a definition for ‘RewardGold’ and no accessible extension method ‘RewardGold’ accepting a first argument of type ‘Enemy’ and Enemy’ does not contain a definition for ‘StealGold’ and no accessible extension method ‘StealGold’ accepting a first argument of type ‘Enemy’ could be found.
i think the problem might be connected to the fact my EnemyMover script is called enemy and my Enemy script is called Enemy2, heres. my script i can send more information if needed.
enemy script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
[SerializeField] List path = new List();
[SerializeField] [Range(1f, 5f)] float speed = 1f;
Enemy enemy;
void OnEnable()
{
FindPath();
ReturnToStart();
StartCoroutine(FollowPath());
}
void Start()
{
enemy = GetComponent<Enemy>();
}
void FindPath()
{
path.Clear();
GameObject[] waypoints = GameObject.FindGameObjectsWithTag("Path");
foreach (GameObject waypoint in waypoints)
{
path.Add(waypoint.GetComponent<Waypoint>());
}
}
void ReturnToStart()
{
transform.position = path[0].transform.position;
}
IEnumerator FollowPath()
{
foreach (Waypoint waypoint in path)
{
// defining variables
Vector3 startPos = transform.position;
Vector3 endPos = waypoint.transform.position;
float travelPer = 0f;
transform.LookAt(endPos);
// while loop
while (travelPer < 1f)
{
travelPer += Time.deltaTime * speed;
transform.position = Vector3.Lerp(startPos, endPos, travelPer);
yield return new WaitForEndOfFrame();
}
}
gameObject.SetActive(false);
enemy.StealGold();
}
}
enemy2 script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy2 : MonoBehaviour
{
[SerializeField] int goldReward = 25;
[SerializeField] int goldPenalty = 25;
Bank bank;
// Start is called before the first frame update
void Start()
{
bank = FindObjectOfType<Bank>();
}
void RewardGold()
{
if(bank = null) { return; }
bank.Deposit(goldReward);
}
void StealGold()
{
if(bank = null) { return; }
bank.WithDrawl(goldPenalty);
}
}