Question by
AgentDreiX · Mar 15, 2021 at 04:17 AM ·
scripting problemgui
Coin-pickup script doesn't work correctly.
This is the script for the coin:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoinScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Rotate(90 * Time.deltaTime, 0, 0);
}
private void OnTriggerEnter(Collider other)
{
if(other.name == "Player")
{
other.GetComponent<PlayerScript>().points++;
//Add 1 to points
Destroy(gameObject); // This destroys things.
}
}
}
And this is the script for the player and the coin counter:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour {
public int points = 0;
// Use this initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
private void OnGUI()
{
GUI.Label(new Rect(10,10,100,20), "Score : " + points);
}
}
But when I test it out, the coin just spins and the coin counter doesn't go up. Also, when the player hits the coin, it will be pushed away like a solid box. How can I fix this? How can I change the text color in the screen GUI directly from the script?
Comment