Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Kineticon · Apr 23, 2019 at 05:24 AM · gameobjectparticlesystemarray of gameobjectscheckpoints

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.

,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

218 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

create array of specific gameobjects 0 Answers

Best way to set game object transforms 2 Answers

Get the transform.position of a gameobject in an array? 2 Answers

Array of objects works half the time! 0 Answers

BCE0019: 'gameObject' is not a member of 'Object'. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges