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 Rokcet · Aug 14, 2014 at 09:49 AM · errorshoot

Shooting script issue?

I recently started working on a game and so far so good but the only issue is the shooting part. I was watching a tutorial on how to do this but it doesn't work because it cant find the Mouselook script even though I have it in my Scripts folder. Is there anyway to fix this?

Here is the script I am using(Java Script): var PlayerTransform : Transform; var PlayerScript : Player; var RotationSpeed : float; var PlayerCamera : GameObject; var IsAiming : boolean = false; var GunAnimationHolder : GameObject;

 //Targets
 
 @HideInInspector
 var TargetXrotation : float;
 
 @HideInInspector
 var TargetYrotation : float;
 
 @HideInInspector
 var TargetXrotationV : float;
 
 @HideInInspector
 var TargetYrotationV : float;
 
 // Gun Specs
 var MaxClipSize : float = 32;
 var AmmoInCurrentClip : float = 32;
 var ExtraAmmo : float = 128;
 var MaxCarringAmmo : float = 256;
 
 //  Bullets and shiz
 var Bullet : GameObject;
 var BulletSpawn : GameObject;
 var BulletSound : GameObject;
 var FireRate : float;
 var FireTimer : float;
 
 //Recoil
 var Recoil : float = 3;
 var RecoilAimingIn : float = 3;
 var RecoilAimingOut : float = 6;
 
 //Reloads
 var ReloadAnimation : GameObject;
 var ReloadSound : AudioSource;
 var Reloading : boolean = false;
 var ReloadName : String;
 
 
 function Update()
 {
 AimingInController();
 }
 
 function AimingInController()
 {
 IsAiming = GunAnimationHolder.GetComponent(Player).AimingIn;
 }
 
 function LateUpdate () 
 {
 
 if (AmmoInCurrentClip > MaxClipSize)
 
 AmmoInCurrentClip = MaxClipSize;
 
 if (ExtraAmmo > MaxCarringAmmo)
 
 ExtraAmmo = MaxCarringAmmo;
 
 if (FireTimer < -5)
 FireTimer = -5;
 
 if (MaxClipSize < 0)
 
 MaxClipSize = 0;
 
 if (AmmoInCurrentClip < 0)
 
 AmmoInCurrentClip = 0;
 
 if (!Reloading && AmmoInCurrentClip < MaxClipSize && ExtraAmmo > 0 && Input.GetButtonDown("Reload")&& IsAiming == false)
     {
         Reloading = true;
         ReloadSound.Play();
         ReloadAnimation.animation.Play(ReloadName);
     }
     
 if (!Reloading && AmmoInCurrentClip == 0 && ExtraAmmo > 0 && Input.GetButtonDown("Fire1") && IsAiming == false)
     {
         Reloading = true;
         ReloadSound.Play();
         ReloadAnimation.animation.Play(ReloadName);
     }
     
 if (Reloading && !ReloadAnimation.animation.IsPlaying(ReloadName))
 {
 if (ExtraAmmo >= MaxClipSize - AmmoInCurrentClip)
 {
 ExtraAmmo -= MaxClipSize - AmmoInCurrentClip;
 AmmoInCurrentClip = MaxClipSize;
 }
 
 if (ExtraAmmo < MaxClipSize - AmmoInCurrentClip)
 {
 AmmoInCurrentClip += ExtraAmmo;
 ExtraAmmo = 0;
 }
 Reloading = false;
 }
 
 var MyBulletSound : GameObject;
 
 if (Input.GetButton("Fire1") && AmmoInCurrentClip > 0 && !Reloading)
 {
 
 if (FireTimer <= 0)
 {
 AmmoInCurrentClip -= 1;
 
 TargetXrotation += (Random.value - 0.5) *Mathf.Lerp (Recoil, RecoilAimingOut,0);
 TargetYrotation += (Random.value - 0.5) *Mathf.Lerp (Recoil, RecoilAimingOut,0);
 
 
 if (Bullet)
 
 Instantiate(Bullet,BulletSpawn.transform.position,BulletSpawn.transform.rotation);
 
 if (BulletSound)
 
     MyBulletSound = Instantiate(BulletSound,BulletSpawn.transform.position,BulletSpawn.transform.rotation);
 
 FireTimer = 1;
 
 }
 
 
 }
 
 if (Input.GetButton("Fire2") && !Reloading )
 {
     Recoil = RecoilAimingIn;
 
 }
 
 if (Input.GetButton("Fire2") == false || Reloading )
 {
     Recoil = RecoilAimingOut;
 
 }
 
 
 FireTimer -= Time.deltaTime * FireRate;
 
 transform.position = PlayerCamera.transform.position + (Quaternion.Euler(0,TargetYrotation,0) * Quaternion.Euler(TargetXrotation,TargetYrotation,0) * Vector3(0,0,0));
 
 TargetXrotation = Mathf.SmoothDamp(TargetXrotation, -PlayerCamera.GetComponent(MouseLook).rotationY,TargetXrotationV,RotationSpeed);
 
 TargetYrotation =Mathf.SmoothDamp(TargetYrotation, PlayerCamera.GetComponent(MouseLook).RotationX,TargetYrotationV,RotationSpeed);
 
 transform.rotation = Quaternion.Euler(TargetXrotation,TargetYrotation,0);
 
 
 }
Comment
Add comment · Show 3
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 robertbu · Aug 14, 2014 at 04:21 PM 0
Share

What specific error are you getting? Edit your question to include a copy of the error from the Console. If the issue is a runtime error, note that this code expects the $$anonymous$$ouseLook script to be attached to the 'PlayerCamera'.

avatar image Rokcet · Aug 14, 2014 at 04:58 PM 0
Share

It seems to be giving me another error and the mouselook one is gone except this error says :

Assets/GunScript.js(154,91): BCE0120: '$$anonymous$$ouseLook.rotationY' is inaccessible due to its protection level.

avatar image robertbu · Aug 14, 2014 at 05:15 PM 0
Share

Open the $$anonymous$$ouseLook script and edit it to make 'rotationY' public. If your $$anonymous$$ouseLook script is identical to the one on my machine, line 31 should be changed to:

   public float rotationY = 0F;

I don't know where you got this script, but this seem like a strange way to solve this problem.

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

very simple shoot script keeps getting error!!! 3 Answers

Script keeps functioning when disabled 1 Answer

Pause script errror. 1 Answer

how do i fix this error 1 Answer

Can't Add Script 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