Every time when I run a game with this script and pick a coin, it doesn’t destroy. Score is multiplied and other coin appear, but coins don’t disappear. Here’s a script:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Movement : MonoBehaviour
{
float rotationSpeed = 10f;
private Rigidbody rb;
float dashLenght = 6f;
int count;
public Text countText;
public GameObject coin;
void CoinSpawn()
{
Vector3 position = new Vector3(Random.Range(7, -15), 1, Random.Range(13, -5));
Instantiate(coin, position, Quaternion.identity);
}
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
ScoreCount();
}
// Update is called once per frame
void Update ()
{
float mov_Vertical = Input.GetAxis("Vertical");
float mov_Horizontal = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3(mov_Horizontal, 0f, mov_Vertical);
//add force for rotation
rb.AddForce(movement * rotationSpeed);
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Coin")
{
CoinSpawn();
Destroy(coin);
count += 1;
ScoreCount();
}
}
void ScoreCount()
{
countText.text = "Score: " + count.ToString();
}
}
If you can help me I really appreciate it.