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
1
Question by Samir 1 · Jan 19, 2011 at 08:05 PM · instantiatepositionlinerendererrespawn

how could you, while holding a button destroy then reinstantiate an object in original position after time?

ok basically im using the line renderer. im trying to move it(and activate it) when i press a button so that it looks like a shot(this works). What i am asking is what do u need to, while holding a button i want to remove it and make it spawn back to its original starting position, after a period of time so it mimics shooting bullet paths like a machinegun.

here is code:

public class TurretLight : MonoBehaviour { public LineRenderer line; public float bulletspeed = 5.0f; public float lifetime = 1.0f;

// Use this for initialization void Start () {

 line.renderer.enabled = false;

}

// Update is called once per frame void Update () {

 if (Input.GetKey("f"))
 {
     line.renderer.enabled = true;

     if(line.renderer.enabled == false)
     {
     Instantiate(line, transform.position, transform.rotation);
     }

     transform.Translate(bulletspeed * Vector3.forward * Time.deltaTime);
     LineRenderer.Destroy(line, lifetime);

 }
 else if (Input.GetKeyUp("f"))
 {
     line.renderer.enabled = false;
 }

}

thanks please just reply if u no the code and how to do this ive tried everyting so far and would appreciate the help. sorry if a question like this has been answered already.

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

1 Reply

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

Answer by fireDude67 · Jan 19, 2011 at 11:36 PM

First you should add these variables:

float time;
bool hasStarted = false;
bool hasEnded = false;
int timeDelay = 3; // Or however long you want your intervals

Then after that, deactivate the object and start the clock

void FixedUpdate() { if (!hasStarted && !hasEnded) { objectToMakeDisappear.gameObject.active = false; time = Time.time; hasStarted = true; }

  else if (hasStarted && Time.time >= time + timeDelay && !hasEnded) {
       objectToMakeDisappear.gameObject.active = true;
       hasEnded = true;
  }

  else if (hasEnded && Time.time > time + timeDelay) {
       hasStarted = false;
       hasEnded = false;
  }

}

This is untested and written in C#

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 Samir 1 · Jan 20, 2011 at 08:01 PM 0
Share

yeh ive figured it out i just made a new empty gameobject, and instantiated a prefab that has a lifetime so it will die, then i said if currenttime > timetospawn then instantiate new object :)

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

Checking the distance between an instantiated object and an existing object 1 Answer

Fire object towards mouse cursor 1 Answer

Setting the position of linerenderer 1 Answer

Instatiating a prefab in a random position 0 Answers

How can I get the x position for the left(and right) of the screen? 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