So I’m using Unity and C# and am currently getting a problem where the ball doesn’t respawn and the score goes up continuously. I’m not sure if this is a coding error or just a unity error. The score thing came up after i put the Paddle Obj on the score script in the deadzones.
This is the coding I’m using:
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public TextMesh currSco;
public GameObject ballPref;
public Transform paddleObj;
GameObject ball;
int score;
void Update ()
{
ball = GameObject.FindGameObjectWithTag("Ball");
currSco.text = "" + score;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Ball")
{
score += 1;
Destroy(ball);
(Instantiate(ballPref, new Vector3(paddleObj.transform.position.x + 2, paddleObj.transform.position.y,0), Quaternion.identity) as GameObject).transform.parent = paddleObj;
}
}
}
And this is the Tutorial I’m using: #4. Score - How to make a Simple 2D Game - Unity 5 Tutorial - YouTube
Can someone help? If you guys need anything else feel free to ask.