Unity/C# Respawn and score Problem
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: https://www.youtube.com/watch?v=0YLDzKkXlME
Can someone help? If you guys need anything else feel free to ask.
Answer by werdna_90 · Jan 28, 2016 at 11:27 AM
I also had this problem. I was copying the paddleObj as an object into the Score script on the inspector.The ball was still a child of the paddleObj once I removed ball from paddleObj within the hierarchy I then put paddeObj into score script again and everything worked fine I am not very good at explaining these things but I hope this helps.
Your answer
Follow this Question
Related Questions
C# Respawn and Score Problem 1 Answer
Highscore table C# HELP!!! 0 Answers
Can PlayerPrefs be accessed in different scripts - c# 2 Answers
Making a high score script 0 Answers