• 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 Xatoku · Feb 17, 2011 at 03:02 AM · projectilebasicadvancedanimating

Shoot Not Letting Me Shoot Twice

In my shooting script, I can shoot on the time of the "meteor" animation at 1.3 fine, but if I try to do it again it will freeze on the last frame and won't produce any projectile. Any body able to help? If my script sucks could someone just write me up one to shoot 1 projectile on the 1.3 time mark (40 frames) of my shooting animation (meteor).

// Movement Variables: private var jumpSpeed:float = 15.0; private var gravity:float = 50.0; private var runSpeed:float = 35; private var walkSpeed:float = 35; private var rotateSpeed:float = 250.0; private var grounded:boolean = false; private var moveDirection:Vector3 = Vector3.zero; private var isWalking:boolean = true; private var isMoveable:boolean = true; private var isCasting:boolean = false; private var isReadyToShoot:boolean = false; private var moveStatus:String = "idle"; private var xSpeed = 250.0; private var ySpeed = 120.0; private var yMinLimit = -40; private var yMaxLimit = 80; private var x = 0.0; private var y = 0.0; private var dead = false; private var savedTime = 0;

var meteorPrefab:Transform;

// ------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------Animations --------------------------------------- // -------------------------------------------------------------------------------------------------------------

function Do1() { yield WaitForSeconds(1.3); isReadyToShoot = true; }

function Do2() { var meteor = Instantiate(meteorPrefab, GameObject.Find("meteorSpawnPoint").transform.position, transform.rotation); meteor.rigidbody.AddForce(transform.forward * 2000); GameObject.Find("meteorSpawnPoint").active= false; yield WaitForSeconds(0.6); isMoveable = true; isWalking = true; isCasting = false; isReadyToShoot = false; } // ------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------- Death --------------------------------------- // -------------------------------------------------------------------------------------------------------------

function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "fallout") { dead = true; //subtract life here HealthControl.LIVES -= 1; } } // ------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------- Movement --------------------------------------- // -------------------------------------------------------------------------------------------------------------

function Update () { // Only allow movement and jumps while ----------------- GROUNDED ------------- if(grounded) { moveDirection = new Vector3((Input.GetMouseButton(1) ? Input.GetAxis("Horizontal") : 0),0,Input.GetAxis("Vertical"));
if(Input.GetMouseButton(1) && Input.GetAxis("Horizontal") && Input.GetAxis("Vertical")) { moveDirection = .7; } moveDirection = transform.TransformDirection(moveDirection); moveDirection = isWalking ? walkSpeed : runSpeed; moveStatus = "idle"; if(moveDirection != Vector3.zero) { moveStatus = isWalking ? "walking" : "running"; if (isWalking) { animation.CrossFade("run"); } else { // call RUN animation here } } else { animation.CrossFade("Take 001"); } } if(isCasting == true) { animation.CrossFade("meteor"); isMoveable = false; isWalking = false; Do1(); } if(isReadyToShoot == true) { Do2(); } // ------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------- Specials ------------------------------------ // -------------------------------------------------------------------------------------------------------------

// Meteor Special

 if(isCasting == false)
 {
     if(Input.GetKeyDown("1"))
     {
         isCasting = true;
     }
 }

// ------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------- Controls ------------------------------------ // -------------------------------------------------------------------------------------------------------------

 // Allow turning at anytime. Keep the character facing in the same direction as the Camera if the right mouse button is down. 
 if(Input.GetMouseButton(1))
 {
     transform.rotation = Quaternion.Euler(0,Camera.main.transform.eulerAngles.y,0); 
 } else { 
     transform.Rotate(0,Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime, 0); 
 } 

 // Toggle walking/running with the T key 
 if(Input.GetKeyDown("t"))
 {
     isWalking = !isWalking; 
 }

 //Apply gravity 
 if(isMoveable)
 {
     moveDirection.y -= gravity * Time.deltaTime; 
 }
 //Move controller 
 if(isMoveable)
 {
     var controller:CharacterController = GetComponent(CharacterController); 
     var flags = controller.Move(moveDirection * Time.deltaTime); 
     grounded = (flags & CollisionFlags.Below) != 0; 
 };
 }
 static function ClampAngle (angle : float, min : float, max : float) { 

if (angle < -360) angle += 360; if (angle > 360) angle -= 360; return Mathf.Clamp (angle, min, max); }

// ------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------- END UPDATE -------------------------------- // -------------------------------------------------------------------------------------------------------------

function LateUpdate() { if(dead) { transform.position = Vector3(1341.832,0.1636853,1158.249); gameObject.Find("Camera") .transform .position = Vector3(1341.832,0.1636853,1135.249); dead = false; } }

// ------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------- END LATEUPDATE -------------------------------- // ------------------------------------------------------------------------------------------------------------- @script RequireComponent(CharacterController)

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 unity3dsramdec · Feb 17, 2011 at 07:25 PM 0
Share

Am i correct in assu$$anonymous$$g that you are suggesting that you want to shoot every 1.3 seconds?

avatar image Xatoku · Feb 17, 2011 at 08:31 PM 0
Share

I want to shoot once at the 1.3 second mark

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Learning From Nothing to Advanced unity scripting for a teen developer!? 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Differences between unity teams basic and advanced 2 Answers

Photon Networking Prefab help 0 Answers

How to make counter still counting after application has quit? 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