- Home /
noob question: My 2d pong ball respawn is bigger than the previous
Hi guys! so I'm just totally new to unity, so my pong ball starts like this:
and then when it respawns:
here is my code for respawning and scoring :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Score : MonoBehaviour
{
public TextMesh currSco;
public GameObject ballPref;
public Transform playerObj;
GameObject ball;
int score;
void Update ()
{
ball = GameObject.FindGameObjectWithTag("Ball");
currSco.text = "" + score;
}
private void OnTriggerEnter(Collider other)
{
if(other.tag == "Ball")
{
score += 1;
Destroy(ball);
(Instantiate(ballPref, new Vector3(playerObj.transform.position.x + 2, playerObj.transform.position.y, 0), Quaternion.identity) as GameObject).transform.parent = playerObj;
}
}
}
Can someone teach me how to fix this? Thanks in advance! :D
Comment
Your answer
Follow this Question
Related Questions
Enemy prefab not keeping transform 2 Answers
Finding a prefab in after respawn 1 Answer
Spawn Object from list, then respawn after "used" 0 Answers