❔ How would i connect a variable between 2 scripts
i have a script for score in my game for collectibles, and i want a mechanic similar to coins from mario kart, where the more you collect the faster you become, so how would i reference this variable in my other code to multiply the movement speed by, here are my scripts
score:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Score : MonoBehaviour
{
public TMP_Text myScoreText;
private int score;
// Start is called before the first frame update
void Start()
{
score = 0;
myScoreText.text = "Score: " + score;
}
private void OnTriggerEnter2D(Collider2D Coin)
{
Debug.Log("Trigger entered!");
if (Coin.tag == "Collectible")
{
score += 1;
Destroy(Coin.gameObject);
myScoreText.text = "Score: " + score;
}
}
}
Movement
1 Reply
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.