Hello! I’m a total Unity beginner and tried myself on a simple pong game. Here I simply instatiated a clone of a prefab ball when hitting space who moves. If it passes a certain x position (which is behind the pong bat) the score should increase. I asume I did simething wrong with the clones? Thanks for answers! (Before implementing hitting space feature and the ball just was there, not as a clone, everything worked)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class count_score : MonoBehaviour
{
public Text Scoreboard;
public GameObject Ball;
private int Bat_1Score;
private int Bat_2Score;
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(Ball, new Vector2(0, 0), Quaternion.identity);
}
if (Ball.transform.position.x >= 11f)
{
Bat_1Score++;
}
if (Ball.transform.position.x <= -11f)
{
Bat_2Score++;
}
Scoreboard.text = Bat_1Score.ToString() + " - " + Bat_2Score.ToString();
print(Bat_1Score + " , " + Bat_2Score);
if (Bat_1Score == 10 || Bat_2Score ==10)
{ Bat_1Score = 0;
Bat_2Score = 0;
Destroy(Ball.gameObject);
}
}
}