Play/Stop particle system from a child object with another script
So I have this checkpoint script with basically indicates if the player has passed the checkpoints. Each checkpoints are stored in an array from another script. All of that is pretty much done. Now the problem I have is that each checkpoint has 2 children, each with a particle system (for visual indicator), and what I'm trying to do is that if the player passes a checkpoint, it stops that specific checkpoint's particle system in its children, and plays the next checkpoints' children's particle system and so on.
this script below is attached to the player and it has all the checkpoints attached to it in the checkpointArray
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Laps : MonoBehaviour
{
// these static variables are accessed in 'checkpoints script'
public Transform[] checkPointArray;
public static Transform[] checkpointA;
public static int currentCheckpoint = 0;
public static int currentLap = 0;
public Vector3 startPos;
public float endLap;
public static float maxLaps;
public int Lap;
public int checkpointNo;
public Text cpCounter;
public Text lapCounter;
public GameObject RaceFinished;
public Text RaceResult;
void Start()
{
foreach (var cpVFX in checkPointArray)
{
cpVFX.GetComponentInChildren<ParticleSystem>().Stop();
}
checkPointArray[0].GetComponentInChildren<ParticleSystem>().Play();
startPos = transform.position;
currentCheckpoint = 0;
currentLap = 0;
RaceFinished.gameObject.SetActive(false);
}
void Update()
{
maxLaps = endLap;
Lap = currentLap;
checkpointA = checkPointArray;
checkpointNo = currentCheckpoint;
hudUpate();
}
void hudUpate()
{
//currentCheckpoint.ToString();
//currentLap.ToString();
cpCounter.text = currentCheckpoint.ToString() + " | " + checkpointA.Length.ToString();
lapCounter.text = currentLap.ToString() + "/" + endLap ;
if(currentLap == (maxLaps + 1))
{
RaceFinished.gameObject.SetActive(true);
RaceResult.text = "you placed 1/1";
}
}
}
this script is where Im having trouble.... in checkpointVisuals()
using UnityEngine;
using System;
using System.Collections;
public class checkpoint : MonoBehaviour
{
static GameObject playerTransform;
private Laps maxLaps;
void Start()
{
playerTransform = GameObject.FindWithTag("Player");
}
void OnTriggerEnter(Collider other)
{
//checks if it is player
if (!other.CompareTag("Player"))
return; //dont continue if not
if (transform == Laps.checkpointA[Laps.currentCheckpoint].transform)
{
if (Laps.currentCheckpoint + 1 < Laps.checkpointA.Length)
{
//Add to currentLap if currentCheckpoint is 0
if (Laps.currentCheckpoint == 0)
Laps.currentLap++;
Laps.currentCheckpoint++;
}
else
{
//goes back to 0 if no more checkpoints avail
Laps.currentCheckpoint = 0;
}
if (Laps.currentLap == (Laps.maxLaps+1))
{
Debug.Log("RACE OVER!");
}
checkpointVisuals();
}
}
void checkpointVisuals()
{
var cpVFX = Laps.checkpointA[Laps.currentCheckpoint].GetComponentInChildren<ParticleSystem>();
//disables passed checkpoint
foreach (ParticleSystem cp in playerTransform.GetComponent<Laps>().checkPointArray)
{
cpVFX.GetComponent<ParticleSystem>().Stop();
}
//enables next checkpoint
playerTransform.GetComponent<Laps>().checkPointArray[Laps.currentCheckpoint].GetComponentInChildren<ParticleSystem>().Play();
}
}
I always get the error checkpoint.cs(57,9): error CS0030: Cannot convert type 'UnityEngine.Transform' to 'UnityEngine.ParticleSystem which is the foreach statement but I have no clue how to fix it.
,