I have looked almost 10 different topics but nothing worked for me.
I have such code
updateScore.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class updateScoreText : MonoBehaviour
{
Text scoreText;
// Start is called before the first frame update
void Start()
{
scoreText = GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
}
public void scoreUpdate(int score)
{
scoreText.text = "Score: " + score;
}
}
I want to call scoreUpdate method in another script
I tried
public updateScore addScoreText;
addScoreText = GameObject.Find(“Text”).GetComponent().scoreUpdate(points);
in another script
but it shows error error CS1061: ‘updateScore’ does not contain a definition for ‘scoreUpdate’ and no accessible extension method ‘scoreUpdate’ accepting a first argument of type ‘updateScore’ could be found (are you missing a using directive or an assembly reference?)
,This is my full error :
error CS1061: ‘updateScore’ does not contain a definition for ‘scoreUpdate’ and no accessible extension method ‘scoreUpdate’ accepting a first argument of type ‘updateScore’ could be found (are you missing a using directive or an assembly reference?)
I have two different scripts
PlayerPoint.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class playerPoint : MonoBehaviour
{
public int points = 0;
float timers = 0.0f;
public int seconds = 0;
bool scoreUpdated = false;
public updateScore addScoreText;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("addPoint",5.0f,5.0f);
}
// Update is called once per frame
void Update()
{
}
void addPoint()
{
if (scoreUpdated == false)
{
points += 5;
addScoreText.scoreUpdate(points);
}
}
}
updateScore.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class updateScoreText : MonoBehaviour
{
Text scoreText;
// Start is called before the first frame update
void Start()
{
scoreText = GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
}
public void scoreUpdate(int score)
{
scoreText.text = "Score: " + score;
}
}
Please could someone help me why I get this error when I already have scoreUpdate method in updateScore.cs file?