Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 156484134616498 · Jun 18, 2017 at 05:41 PM · animationissueplay

About Shooting With Gun

Hi.I made An animation for my gun called "shootwithm9" i have a bullet called "Bullet" and i wrote a script for shooting and im getting errors this is my script:

 using UnityEngine;
 using System.Collections;
 
 public class M9 : MonoBehaviour {
 
     public Transform M9bullet;
     public Transform BulletSpawn;
 
     public int OurAmmo = 100;
 
     private RaycastHit hit;
     private Vector3 dir;
     private Quaternion rot;
 
     // Use this for initialization
     void Start () {
 
     }
 
     // Update is called once per frame
     void Update () {
         if (animation.isplaying("shootwithm9") == false) {
             if (Input.GetButtonDown ("Fire1")) {
                 if (OurAmmo > 0) {
                     Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0));
 
                     if (Physics.Raycast(Ray, out hit)) {
                         dir = (hit.point - BulletSpawn.position).normalized;
                     }
                     else {
                         dir = ray.direction;
                     }
                     rot = Quaternion.FromToRotation (-M9bullet.transform.forward, dir);
                     Instantiate(M9bullet, BulletSpawn.position, rot);
                     Animation.Play ("shootwithm9");
                     audio.Play();
                     OurAmmo -= 1;
                 }
             }
         }
         //CheckAmmo
     }
 }

Check The Script. Thank you and sorry for bad english

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 JxWolfe · Jun 18, 2017 at 07:20 PM 0
Share

What's the error? The message tells a lot about where, and what the problem is if you can read it

avatar image 156484134616498 JxWolfe · Jun 18, 2017 at 08:17 PM 0
Share

alt text

all errors

untitled.png (40.0 kB)

2 Replies

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

Answer by JxWolfe · Jun 18, 2017 at 08:30 PM

Ok i looked at the code and came up with this

 using UnityEngine;
 using System.Collections;
 
 //just to make sure the animation component is on the object
 [RequireComponent(Animation)]
 
 public class M9 : MonoBehaviour {
 
     public Transform M9bullet;
     public Transform BulletSpawn;
 
     public int OurAmmo = 100;
 
     private RaycastHit hit;
     private Vector3 dir;
     private Quaternion rot;
 
     //problems found that i found ##############################################################33
     Animation yourAnimation;
     AudioSource yourAudio;
 
     // Use this for initialization
     void Start () {
         yourAnimation = GetComponent<Animation> ();
     }
 
     // Update is called once per frame
     void Update () {
         if (yourAnimation.IsPlaying("shootwithm9") == false) {
             if (Input.GetButtonDown ("Fire1")) {
                 if (OurAmmo > 0) {
                     Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0));
 
                     if (Physics.Raycast(Ray, out hit)) {
                         dir = (hit.point - BulletSpawn.position).normalized;
                     }
                     else {
                         dir = ray.direction;
                     }
                     rot = Quaternion.FromToRotation (-M9bullet.transform.forward, dir);
                     Instantiate(M9bullet, BulletSpawn.position, rot);
                     yourAnimation.Play ("shootwithm9");
                     yourAudio.Play();
                     OurAmmo -= 1;
                 }
             }
         }
         //CheckAmmo
     }
 }

I think it should work, and if i doesn't then post the new errors and i will take another look.

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 JxWolfe · Jun 18, 2017 at 08:32 PM 0
Share

the error messages helped

avatar image 156484134616498 · Jun 18, 2017 at 08:39 PM 0
Share

Thank You It's Very Nice. But We Have 3 Errors With This line:

 [RequireComponent(Animation)]

These Are Errors: alt text

sorry for my questions I'm new

avatar image JxWolfe · Jun 18, 2017 at 08:40 PM 0
Share

just get rid of it, i am new to requiring components, and it would only add the animation component if it wasn't on the object

avatar image
0

Answer by 156484134616498 · Jun 18, 2017 at 09:32 PM

Thank You It Worked

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 JxWolfe · Jun 18, 2017 at 10:49 PM 0
Share

:) glad to hear it!

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

158 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Preventing all animations from playing? 0 Answers

Character won't play animation 8 Answers

Animation Play Problem (Att: Video Example) 1 Answer

animation play in game over 1 Answer

How to Play an Animation in Unity 4.5.3? 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