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 nicole · Aug 30, 2010 at 02:55 AM · charge

how to recollect the power object after it generate the power for few seconds

my pick up script:

var CoconutCount : int = 0; private var speed = 20; private var moveDirection = Vector3.zero;

function Update(){ if(CoconutCount >= 4){

     controller = GetComponent(CharacterController);
     transform.eulerAngles.y += Input.GetAxis("Horizontal") ;

     moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
     moveDirection = transform.TransformDirection(moveDirection);
     moveDirection *= speed;
     controller.Move(moveDirection * Time.deltaTime);

 }

}

function OnTriggerEnter(collisionInfo : Collider){ if(collisionInfo.gameObject.tag == "Coconut"){ CoconutCount++; //audio.PlayOneShot(batteryCollect); Destroy(collisionInfo.gameObject); } }

my collect script:

var GUICoconut : GameObject; var CoconutCount : int;

var Coconut1tex : Texture2D; var Coconut2tex : Texture2D; var Coconut3tex : Texture2D; var Coconut4tex : Texture2D; var Coconut0tex : Texture2D;

function Start(){ //GUICoconut = GameObject.FindWithTag("CoconutGUI"); GUICoconut.guiTexture.texture = Coconut0tex; }

function Update(){ CoconutCount = this.GetComponent("PickUp").CoconutCount; if (CoconutCount == 1) { GUICoconut.guiTexture.texture = Coconut1tex; } else if (CoconutCount == 2) { GUICoconut.guiTexture.texture = Coconut2tex; } else if (CoconutCount == 3) { GUICoconut.guiTexture.texture = Coconut3tex; } else if (CoconutCount >= 4) { GUICoconut.guiTexture.texture = Coconut4tex; } }

Comment
Add comment · Show 1
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 _Petroz · Aug 30, 2010 at 05:22 AM 0
Share

You question is unclear and your code should be formatted as code so it is readable.

1 Reply

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

Answer by spinaljack · Aug 30, 2010 at 08:10 AM

Instead of using destroy use renderer.enabled = false to hide it and then after a few seconds re-enable it.

e.g.

function OnTriggerEnter(collisionInfo : Collider){
    if(collisionInfo.gameObject.tag == "Coconut" && collisionInfo.gameObject.renderer.enabled){
        CoconutCount++;
        //audio.PlayOneShot(batteryCollect);
        collisionInfo.gameObject.SendMessage("RendererOff");
    }
}

On the item do this to turn it back on:

var offTime : float;

function Update(){ if(!renderer.enabled && Time.time-offTime > 10){ renderer.enabled = true; } }

function RendererOff(){ renderer.enabled = false; offTime = Time.time; }

Comment
Add comment · Show 2 · 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 nicole · Aug 30, 2010 at 09:17 AM 0
Share

actually what i wants to achieve is when the character collect four coconuts,his walking speed will generate faster for 5 seconds, the after 5 seconds, his speed will reduce back to normal unless he need to recollect the four coconuts again...and how am i going to deal with my GUI..back to the empty bar when the character is generating power..

thx alot!!

avatar image spinaljack · Aug 30, 2010 at 09:53 AM 0
Share

Just set coconut count to 0 after a few seconds of collecting the 4th coconut. Use the same time stamp method.

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

Any idea on this flash/charge effect 2 Answers

Using the increasing and decreasing value function to deal damage 2 Answers

Power up weapon shot before releasing and resetting power 1 Answer

How would you make an object behave like a magnet? 1 Answer

Animation depending on int 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