i want to call my iscore function from gamemanager script in target script but it is showing error
error CS1656: Cannot assign to 'iscore' because it is a 'method group' and error CS1503: Argument 1: cannot convert from 'method group' to 'object' coming
this is my gamemanager script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public GameObject target;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("Spawn", 1f, 1f);
}
// Update is called once per frame
void Update()
{
}
void Spawn()
{
float randomX = Random.Range( -7f,7f);
float randomY = Random.Range(-3.5f, 3.5f);
Vector3 randomPosition = new Vector3(randomX, randomY, 0);
Instantiate(target,randomPosition, Quaternion.identity);
}
public void iscore()
{
iscore++;
Debug.Log(iscore);
}
}
and this is my target script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class target : MonoBehaviour
{
public GameManager gameManager;
int score = 0;
// Start is called before the first frame update
void Start()
{
gameManager = GameObject.Find("GameManager").GetComponent();
Destroy(gameObject,2f);
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
gameManager.iscore();
Destroy(gameObject);
}
}
can someone help me
↧