Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 rutwikd95 · Sep 11, 2016 at 04:59 PM · instantiatepositionparticlesystem

How to Instantiate a particle system at a certain prefab's position?

So i am working on a game where the player (ball) rolls through the level and collects coins. I want to add a vfx i made using the particle system at the the coins position when it is collected.How do i do that? The game is actually an endless runner type game and the levels are generated as the the player moves forward and each level is actually a pre-made prefab which has obstacles and coins. So how do i add effect on the coins position that was just collected? Here is the code :

using UnityEngine; using System.Collections; using UnityEngine .UI ;

public class ScoreManager : MonoBehaviour {

 private float score = 0.0f;
 private int DifficultyLevel=1;
 private int MaxDifficultyLevel = 20;
 private int ScoreToNextLevel = 2;
 public Text YourScoreText;

 private bool IsInvincible ;

 public Text ScoreText;


 public Animator GameoverAnim;

 public Renderer Ball;
 public Material RedBall;
 public Material YellowBall;

 public GameObject coinfx;

   


 

 // Use this for initialization
 void Start () {

     IsInvincible = false;
 
 }
 
 // Update is called once per frame
 void Update () 
 {

     if (score >= ScoreToNextLevel && IsInvincible ==false)
         LevelUp ();
     score += Time.deltaTime;
     ScoreText.text = ((int)score).ToString (); 

 
 }


 void LevelUp()
 {
     if (DifficultyLevel == MaxDifficultyLevel)
         return;
     ScoreToNextLevel *= 2;
     DifficultyLevel++;
     GetComponent <PlayerController > ().SetSpeed (DifficultyLevel );
 }


 void OnTriggerEnter(Collider trig)
 {
     if (trig.gameObject.tag == "Obstacle" && IsInvincible == false)
     {

         //YouLoseCanvas.SetActive(true);

         //Time.timeScale = 0;


         StartCoroutine(gameover());

     }

     else if (trig.gameObject.tag == "InvincibleCoin")
     {

         StartCoroutine(InvincibilityActivate());
     }

     else if (trig.gameObject.tag == "Coin")
     {

         Instantiate(coinfx, );
     
         score = score + 5;
         ScoreText.text = ((int)score).ToString();
         Destroy(trig.gameObject);


     }



 }

 IEnumerator gameover()
 {


     GameoverAnim.SetTrigger ("GameOver");

     YourScoreText.text = "You Scored : " +((int)score).ToString (); 

     if(PlayerPrefs .GetFloat ("Highscore") < score )
     PlayerPrefs.SetFloat ("Highscore", score);

     yield return new WaitForSeconds (1);

     Time.timeScale = 0;



     Debug.Log("GAME OVER !!");     
 }



  IEnumerator InvincibilityActivate()
 {

     IsInvincible = true;
     Ball.material = RedBall;

     GetComponent <PlayerController > ().SetSpeed (20 );

     yield return new WaitForSeconds (5);

     Ball.material = YellowBall;

     GetComponent <PlayerController > ().SetSpeed (DifficultyLevel );

     IsInvincible = false;

} }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Cherno · Sep 11, 2016 at 07:06 PM

 Instantiate(coinfx, trig.transform.position, Quaternion.identity) as GameObject;

      

The Scripting API is your friend :)

Comment
Add comment · Show 1 · Share
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
avatar image rutwikd95 · Sep 12, 2016 at 08:20 AM 0
Share

This Worked .! Thanks a Lot :) I know this was a very silly question but i am new to unity and coding in general :P Also thanks for the Scripting API link :)

avatar image
1

Answer by iabulko · Sep 12, 2016 at 01:06 AM

Add to coin prefab a child gameobject called "CoinFX" that already has a component of ParticleSystem with setup effect. Now - when you collect coin: Play coin fx particles and do not destroy object for now (to not destroy fx), just turn off the renderer. Eventually you can destroy it after effect will end

 trig.Find("CoinFX").GetComponent<ParticleSystem>().Play();     
 (trig.GetComponent<Renderer>() as MonoBehaviour).enabled = false;
Comment
Add comment · Show 1 · Share
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
avatar image rutwikd95 · Sep 12, 2016 at 08:22 AM 0
Share

Thanks a lot :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Gameobjects instantiating in the wrong position 0 Answers

Wrong position (always 0,0,0) when Instantiate prefab. 1 Answer

How can I change position of instantiate objects (clones)? 1 Answer

How to Instantiate decals where particles from particle system hits? 1 Answer

2D Unity Instantiate Ragdoll, same Transform as Sprites ( Head, Torso, LArm,RArm,LLeg,RLeg) 2 Answers


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