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 Bram 1 · Dec 26, 2010 at 01:14 PM · timeturretreload

Turret script TT longer reloading

Hello, this is the turret script of the tornado twins tutorial. But it works fine ! but how to I get more time between the shooting, so it takes longer for him to reload. now it is about 2 seconds.. how do i make that 5 seconds ? thanks

//CODE

var LookAtTarget:Transform; var damp = 6.0; var bullitPrefab:Transform; var savedTime;

function Update () { if(LookAtTarget) { var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);

transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);

var seconds : int = Time.time; var oddeven = (seconds % -2);

if(oddeven) {

Shoot(seconds);

} } }

function Shoot(seconds) {

if(seconds!=savedTime) {

var bullit = Instantiate(bullitPrefab ,transform.Find("spawnPoint").transform.position , Quaternion.identity); bullit.rigidbody.AddForce(transform.forward * 1000);

savedTime=seconds; }

}

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
Best Answer

Answer by The_r0nin · Dec 26, 2010 at 01:49 PM

var lookAtTarget:Transform; var damp: float = 6.0; var bullitPrefab:Transform; var savedTime: float; var reloadTime: float = 5.0;

function Update () { if(lookAtTarget) {

     var rotate: Quaternion = Quaternion.LookRotation(lookAtTarget.position - transform.position);

     transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);

     var seconds : float = Time.time;

     if((seconds - savedTime) > reloadTime) {

        Shoot();
        savedTime = seconds;

     }
 }

}

function Shoot() {

 var bullit: GameObject = Instantiate(bullitPrefab , transform.Find("spawnPoint").transform.position, Quaternion.identity);
 bullit.rigidbody.AddForce(transform.forward * 1000);

}

All you want to do is save the time when you shoot, then keep checking if the time NOW is 5 seconds (or whatever your delay is) more than when you saved the time. Also, get in the habit of explicitly declaring variable types... it'll save headaches and game-cycles later... (Oh, and variable names normally start with a lowercase letter... that's sloppy coding on their part...)

Comment
Add comment · Show 3 · 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 Bram 1 · Dec 26, 2010 at 06:58 PM 0
Share

hello. it's not working. this is what's happening: first it waits.. and than it sprays so much rockets that it destroys itself. what's wrong ?

avatar image Bram 1 · Dec 26, 2010 at 07:00 PM 0
Share

Ok now it's working i removed the part " :gameobject " at bullit = Instantiate.. it's now working :D

Thank you ! :D

avatar image The_r0nin · Dec 26, 2010 at 11:34 PM 0
Share

No problem. Please be sure to click the check mark next to the answer, so everyone knows that it has been solved.

avatar image
0

Answer by thendricks · Aug 15, 2012 at 03:16 PM

I tried using the same script for my turret and all that comes up in the console is NullReferenceExeption (it looks at me but it doesn't shoot

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

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

1 Person is following this question.

avatar image

Related Questions

Shoot Script Reload Help 1 Answer

Possibility of adding More than One Projectile 1 Answer

I need a turret script 4 Answers

how to make triger fireball not to pass through spesific objects 2 Answers

Easy Animation/Modeling question 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