Question by
The_Ideator · Jun 07, 2021 at 09:23 AM ·
scripting problemscripting beginnerscriptingbasicsscript error
Making a game where objects need to be shot off of a surface. level complete when all objects are shot off. difficulty in scripting for level completion.
this is the script I am using: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LevelComplete : MonoBehaviour {
private GameObject target;
private void Start()
{
target = GameObject.FindWithTag("Obstacle");
}
// Update is called once per frame
void Update()
{
List<float> obstaclePosition = new List<float>();
obstaclePosition.Add(target.transform.position.y);
for( int i = 0; i<obstaclePosition.Count;i++);
{
if (obstaclePosition[i]<-3)
{
Debug.Log("level complete");
}
}
my understanding:
obstaclePosition is a list that contains all y axis position of objects tagged as obstacle
as it is updated every frame , it will always have number of elements equal to objects tagged obstacle
when all elements are lesser than -3 , console should display level complete
problems: 1. Null Reference Exception 2. Will my program work as intended after the null reference exception is sorted ?
Comment