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 Mai hime · Apr 23, 2011 at 12:34 PM · gameobjectdestroy

Duplicate a code sheet for each game object

Hi everyone, in my game i want the layer to climb the stairs.Each step can hold him for seconds before collapse . The code worked just fine with one step but when i ayyach it to multiple steps and the player collide with the first one all the steps collapse at the same time.

**//the time that one step can hold the player
var stillTime=2.0;
var hitEnter:float;
function OnCollisionEnter()
{
  hitEnter=Time.time;
}
function Update()
{
   if(Time.time>(hitEnter+stillTime))
    {
      Destroy(gameObject);
      print("i can't support you any longer :p");
    }
}**

Do i have to attach a different code sheet to every step ??

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 Toxic Blob · Apr 23, 2011 at 12:40 PM 0
Share

From the code you have here you'll need to attach the script to each step.

avatar image Mai hime · Apr 23, 2011 at 12:56 PM 0
Share

The problem is not in attaching the code to each step but in duplicating the code sheet for each step step1=> code1 step2=> code 2 ...

2 Replies

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

Answer by Mai hime · Apr 23, 2011 at 01:21 PM

The code work fine when i use triggers

function OnTriggerEnter() { yield WaitForSeconds(2); Destroy(gameObject);

}

i attached two collider to each step one as trigger and the other for colliding thank you for helping me

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
avatar image
0

Answer by Bunny83 · Apr 23, 2011 at 01:00 PM

Your problem is that if you don't collide with the platform your hitEnter time will be "0". Therefore all platforms will collapse after two seconds.

Do something like:

var stillTime = 2.0; var hitEnter = 0.0; function OnCollisionEnter() { if (hitEnter == 0.0) { hitEnter = Time.time; } }

function Update() { if((hitEnter > 0.0) && (Time.time>(hitEnter+stillTime))) { Destroy(gameObject); print("i can't support you any longer :p"); } }

That will only allow a platform to collapse when you have set a time. It also prevents the "retriggering" of the time when touching the platform again.

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 Mai hime · Apr 23, 2011 at 01:11 PM 0
Share

it doesn't work the step don't collapse

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

No one has followed this question yet.

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Destroy Object when scene loads 1 Answer

object does not destroy 1 Answer

How to destroy a transform's parent object. 1 Answer

How to delay lines of code. 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