I'm running into an error while building a target that gives you points when hit with a ball. Can someone please help me?
my code:
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public class Points : MonoBehaviour
{
[SerializeField]
private float startTime = 60f;
[SerializeField]
private PlayerController player;
private float timeLeft;
private int score = 0;
[SerializeField]
private Target[] targets;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < targets.Length; i++)
{
targets[i].points = this;
}
}
public void Respawn() //this is where I'm getting the problem
{
timeLeft = startTime;
score = 0;
for (int i = 0; i < targets.Length; i++)
{
targets[i].Respawn();
}
player.Respawn();
}
public void AddScore(int morePoints)
{
score += morePoints;
UnityEngine.Debug.Log($"I now have a score of {score}!");
}
// Update is called once per frame
void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0)
{
UnityEngine.Debug.Log($"The final score was {score}!");
Respawn();
}
}
}
↧