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 Phosphorus2500 · Apr 05, 2016 at 02:54 PM · animationinstantiatespawn

How to do a Spawn Animation

Hi all,

This is my second question (first in a while) and it's probably something incredibly simple that I'm being too dense to realise! (Newb here trying to figure out as much as possible by myself with learning C# and how to use Unity.)

I currently have a saved prefab that is being instantiated at the position of a game object selected at random from an array. I'm looking for a way to make some kind of "visual indicator" either to show what position the object is about to spawn at, or to play an animation on the prefab that is triggered when it first enters the scene.

The purpose of this is to give the player advanced notice and/or extra time to figure out where the object is spawning and get into position. I've tried to do a very simple animation but can't figure out how to get it to play when the prefab is instantiated.

A solution to the above, or any other suggestion that provides either a visual indicator of spawn position, or spawn animation of the prefab when instantiated, would be greatly appreciated!

Edit extra info of what I currently have tried

At the moment, I have an Animation Controller set up on the prefab, and Default animation has a transition to the Spawn Animation clip I created in Unity. There is a transition between the two with a trigger set up, the idea I currently have being to trigger this when the prefab is instantiated into the scene, so the animation plays when the prefab enters the scene.

My problem is, I have absolutely no idea what code will check the prefab has been instantiated into the scene, then set off the trigger so the animation will play. Maybe it's something really obvious that I'm missing, but to be pointed in the right direction would be very helpful.

Thanks all.

Comment
Add comment · Show 2
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 meat5000 ♦ · Apr 05, 2016 at 03:12 PM 0
Share

Show us what you've tried so we've got something to work from and we are not re-doing the same thing.

avatar image Phosphorus2500 meat5000 ♦ · Apr 07, 2016 at 02:34 PM 0
Share

Of course.

At the moment, I have an Animation Controller set up on the prefab, and Default animation has a transition to the Spawn Animation clip I created in Unity. There is a transition between the two with a trigger set up, the idea I currently have being to trigger this when the prefab is instantiated into the scene, so the animation plays when the prefab enters the scene.

$$anonymous$$y problem is, I have absolutely no idea what code will check the prefab has been instantiated into the scene, then set off the trigger so the animation will play. $$anonymous$$aybe it's something really obvious that I'm missing, but to be pointed in the right direction would be very helpful.

Thanks :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MXPServer20953OneTechGuy · Feb 12, 2021 at 02:17 AM

@Phosphorus2500 ,

this is the way to do it:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class spawnsys : MonoBehaviour
 {
     public GameObject Object;
     public float spawnT;
     public float spawnD;
     public bool stopSpawning = false;
     AudioSource audioSource;
     public AudioClip impact;
     public ParticleSystem M;
     // Start is called before the first frame update
     void Start()
     {
         InvokeRepeating("spawn", spawnT, spawnD);
     }
 
     // Update is called once per frame
     void spawn()
     {
         Instantiate(Object, transform.position, transform.rotation);
         M.Play();
         if (stopSpawning)
         {
             CancelInvoke("spawn");
         }
     }
 }
Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

Instantiate prefab 0 Answers

Why do I keep getting 'The object you want to instantiate is null' warning? 1 Answer

Instantiate PreFab on trigger location 0 Answers

Spawn Objects on Grid - how to define size? 1 Answer

Instantiating gameObjects, adding them to a list then moving every gameObject in the list.,Moving gameobjects in gameobject list 0 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