Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Kaws4u · Jun 17, 2015 at 04:58 AM · collisionobjectrespawnosc

Re-spawn Object Help!

*Hello, Im doing a college project in which I have to send OSC messages to Pure Data, I need that object to re-spawn once it is destroyed by the collision with the ball (player)... Once the ball collides with the object, OSC is sending 1000s of messages to pure data instead of one. I want a single message to be sent when I hit the coin and then I want the coin to then, re-spawn. This is the code!

pragma strict

var coinEffect : Transform;

var oscRef : OSCTestSender2Jump;

var respawnTimer : float;

var collectedItem : float;

var delayTime : float;

var objectPrefab : Transform;

function OnTriggerEnter (info : Collider)

{ if (info.tag == "Player")

 {
     Debug.Log("Add coin counter here!");
     Instantiate(coinEffect, transform.position, transform.rotation);
     oscRef.coinCollide();
     Destroy(gameObject);

     if(collectedItem){
         respawnTimer += Time.deltaTime;
         if(respawnTimer > delayTime){
             var newObject = Instantiate(objectPrefab, transform.position,
             transform.rotation);
             respawnTimer = 4.0;
         }
     }
 }


}

Thanks!

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
2

Answer by alok-kr-029 · Jun 17, 2015 at 05:51 AM

why dont you use a bool as a flag eg . private bool flag = true; before collision just check if the flag is true once the collision is success turn the flag to be false ;

hope this will help

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 Kaws4u · Jun 17, 2015 at 06:30 PM 0
Share

I am a complete noob in coding, could you please explain what you mean in more detail please?

avatar image
1

Answer by ArkaneX · Jun 19, 2015 at 01:19 PM

Please check if the "Add coin counter..." message is logged once or multiple times.

If once, then problem probably lies inside coinCollide method. If multiple times, then it means that new instance of coin is immediately created, collide with player, send message, is marked as destroyed, spawn another coin, and the process continues. This can happen, if collectedItem condition is true and deltaTime

On the other hand, if deltaTime is greater than 4.0, instantiate code will probably never be called.

Anyway, the code won't work properly. I suggest that you don't destroy the object at all and then reinstantiate it, but just hide it for a given amount of time, and then show it again.

Comment
Add comment · Show 5 · 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 Kaws4u · Jun 19, 2015 at 01:54 PM 0
Share

"Add coin counter" is logged only once! I am a complete noob in coding, so i do not know how to hide and unhide the object! Could you please explain?

avatar image Kaws4u · Jun 19, 2015 at 01:56 PM 0
Share

the coin collide function in the OSC plugin is

public function coinCollide(){ osc$$anonymous$$ = Osc.StringToOsc$$anonymous$$essage("/melody"); oscHandler.Send(osc$$anonymous$$); }

avatar image ArkaneX · Jun 29, 2015 at 10:10 PM 0
Share

Quick way to hide and unhide after 4 seconds:

 void OnTriggerEnter(Collider info)
 {
     this.gameObject.SetActive(false);
     Invoke("Enable", 4f);
 }
 
 private void Enable()
 {
     this.gameObject.SetActive(true);
 }
avatar image Kaws4u · Jun 30, 2015 at 09:02 PM 0
Share

Thank you so much, you don't know how much you have helped me here... Is there a way to make the respawn shorter than 4 seconds, if not, no problem, I can now do what I've tried to achieve for a very long time - thanks to you!

avatar image ArkaneX · Jul 01, 2015 at 06:53 AM 0
Share

Sure - I put 4 as an example, but you can change it to anything you want. Second parameter in Invoke method is number of seconds. 'f' suffix denotes a float variable, so that you're not limited to integer numbers, and can use for example 2.5f

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I send OSC messages from objects upon collision? 0 Answers

on collision, show/hide other model scripting ? 1 Answer

Cannot move FPSController after respawning at a spawn point. 1 Answer

Checking Object Collision Without Script 1 Answer

Can an object to transfer to another as it increases your speed? 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