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 Wesley S · Jan 05, 2011 at 07:37 PM · objectgamehide

hide game object problems

hey i need help i have created a script but it does not work as i wanted it to. ihave an pointlight on the tip of my gun with an animation it goes from invisible to visible and than invisible. its for simulating the light of the gun firing when i getbutton("Fire1") im firing and i see the light flikkers thats good but then when i getbuttonUp ("Fire1") it disapears thats what i want but now it comes i want it to when i ("Fire1") again that its flikkering again.

can somebody please get this done for me becouse i can`t. dont know whats wrong Again.sorry for that.

function Update() 

{

if( Input.GetButton( "Fire1" ) ) { gameObject.active = true; animation.Play("new gun fire light"); } if( Input.GetButton( "Fire1" ) ) { gameObject.active = false; animation.Play("new gun fire light"); } if( Input.GetButton( "Fire1" ) ) { gameObject.active = active = true; animation.Play("new gun fire light"); } } function Awake() { if( Input.GetButton( "Fire1" ) ) { gameObject.active= true; gameObject.active= false; animation.Play("new gun fire light"); } }

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
1

Answer by kennypu · Jan 05, 2011 at 08:42 PM

whats exactly not working? The code you're using doesn't work because you set active to true in update, then right on the next line, it becomes false. you have to set a timer, or have it delay some how so that you can actually see the light.

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
1

Answer by Ejlersen · Jan 05, 2011 at 09:01 PM

Your code doesn't work as you explain as stated by kennypu, but here is a quick example of how you could make it:

// Our light source public var lightSource : Light;

// Speed of the flicker public var flickerSpeed : int = 10;

// Lets store the flicker time, such that we don't have to calculate it more than once private var flickerTime : float = 0.0f; // Rest before next flicker private var flickerRestTime : float = 0.0f;

function Awake() { // Lets calculate the time between each flicker flickerTime = 1.0 / flickerSpeed; flickerRestTime = flickerTime; }

function Update() { // If we get button up, then lets reset it all to default if(Input.GetButtonUp("Fire1")) { lightSource.enabled = false; flickerRestTime = flickerTime; }

 // If we are holding down the button, then
 if(Input.GetButton("Fire1"))
 {
     // subtract the time since last frame
     flickerRestTime -= Time.deltaTime;

     // If the time is less than 0, then lets make the light turn on/off
     if (flickerRestTime < 0.0f)
     {
         // Set the light source to the opposite of what it was before
         lightSource.enabled = !lightSource.enabled;

         // Reset the time
         flickerRestTime = flickerTime;
     }
 }

}

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 Wesley S · Jan 09, 2011 at 01:24 PM 0
Share

yah tanks this was what i was looking for thanks only i have sett the speed from 10 t0 50 but tanks great work im greatful

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

game object hide 1 Answer

throw / fling object or prefab 1 Answer

Respawning script question. 1 Answer

Help With LookAt Target 1 Answer

End game then an Object is close to another object? 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