calling a value between 2 scripts
I'm having trouble transporting a value from one script to another. the Idea is the player can pick up multiple items that grant a varying amount of points. the point value is then sent to a total amount and to another script displaying the point value above the player's head. the total amount works fine,but the second script displays the correct amount only half the time (in this example its either 0 or 50.) I'm guessing the value is not being stored before its sent to the other script. there a better way of sorting the point value?
//the follower item, worth 50 points
if (collider.gameObject.tag == "Player" && PlayerControler.followerPlayer == 1)
{
//followerPoints = 50f;
following = true;
transform.SetParent(null);
target = GameObject.FindGameObjectWithTag("tail_01");
timeDelay = Time.deltaTime * 10f;
playerControler.HealthCheck();
Debug.Log("current follower number " + PlayerControler.followerPlayer);
Points(50f);
this.gameObject.tag = "objFollower1";
}
public float Points(float followerPoints)
{
pointAnswer = followerPoints;
targetPlayer = GameObject.FindWithTag("Player");
scoreScript.scoreValue = scoreScript.scoreValue + followerPoints;
SpawnPopupPoint();
return followerPoints;
}
public void SpawnPopupPoint()
{
Instantiate(popUpPoint, targetPlayer.transform.position,
Quaternion.identity);
Debug.Log("points" + pointAnswer);
}
the second script
{
public Animator textSlide;
public TextMesh pointText;
public Follower followerScript;
void Start()
{
followerScript = GameObject.FindObjectOfType<Follower>();
AnimatorClipInfo[] clipInfo = textSlide.GetCurrentAnimatorClipInfo(0);
Destroy(this.gameObject, clipInfo[0].clip.length);
pointText.GetComponent<TextMesh>().text = followerScript.pointAnswer.ToString();
}
}
Your answer
Follow this Question
Related Questions
Script not returning value to other script 1 Answer
Function won't be called 1 Answer
The type or namespace function could not be found 1 Answer
[SOLVED]My code line don't execute 1 Answer
Coroutine Freezes Editor with "Out of memory" Error 0 Answers