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
0
Question by NovaDrox · Dec 18, 2016 at 02:17 AM · gungun script

How to make my gun shoot down [C#]

So, I have my gun and it can shoot up and and forward, but not down. Its a 3rd person shooter, and the shooting system is click and fire where the courser is. Can someone help me out?

using UnityEngine; using System.Collections;

public class Shoot : MonoBehaviour { [Range (0, 50)] public int Change_Despawn_Bullet; [Range(0, 50)] public int Bullet_Forward_Force; [Range(0, 50)] public int WaitTimeRelaod; [Range(0, 100)] public int ClipSize_Number = 12; [Range(0, 100)] public int AmmoSize_Number = 36;

 public Transform playerTransform;
 public float offset = 90;
 private GameObject tempGameObject;
 public GameObject Bullet;
 public GameObject Bullet_Spawner;

 private Damage_Heal ammo_clip;

 private void Start()
 {
     ammo_clip = GetComponent<Damage_Heal>();

     tempGameObject = new GameObject();
     ammo_clip.UpdateAmmo_ClipBar();
     ammo_clip.AmmoSize = AmmoSize_Number;
     ammo_clip.ClipSize = ClipSize_Number;

     if (playerTransform == null)
     {
         playerTransform = GameObject.FindWithTag("Player").transform;
     }
 }

 public void Update()
 {
     ammo_clip.UpdateAmmo_ClipBar();

     if (Input.GetKeyDown("r"))
     {
         StartCoroutine("Reload_Animation");    
     }

     RaycastHit hit = new RaycastHit();
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

     if ((Physics.Raycast(ray, out hit)) &&
         (Bullet_Spawner != null) &&
         (Bullet != null) &&
         (ammo_clip != null) &&
         (ammo_clip.ClipSize > 0) &&
         (Input.GetButtonDown("Fire1")))
     {
         Gun_Controll(hit);
     }
 }

 IEnumerator Reload_Animation()
 {
     while ((ammo_clip != null) && ammo_clip.ClipSize >= 0 && ammo_clip.ClipSize < 12 && ammo_clip.AmmoSize > 0)
     {
         yield return new WaitForSeconds(WaitTimeRelaod);

         ammo_clip.AmmoSize -= 1;
         ammo_clip.ClipSize += 1;
         ammo_clip.UpdateAmmo_ClipBar();
     }
 }

 public void Gun_Controll(RaycastHit hit)
 {
         tempGameObject.transform.LookAt(hit.point);

         GameObject Temporary_Bullet_Handler;
         Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Spawner.transform.position, Bullet_Spawner.transform.rotation) as GameObject;
         Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);

         Rigidbody Temporary_RigidBody;
         Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent<Rigidbody>();
         Temporary_RigidBody.AddForce(tempGameObject.transform.forward * Bullet_Forward_Force * 100);
         tempGameObject.transform.LookAt(hit.point);
         Destroy(Temporary_Bullet_Handler, Change_Despawn_Bullet);

         ammo_clip.ClipSize -= 1;
         ammo_clip.UpdateAmmo_ClipBar();

     }
 }
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 roman_sedition · Dec 18, 2016 at 02:32 AM 0
Share

Can't see any code related to how the character is ai$$anonymous$$g or moving, or whether this is a 1st person or 3rd person shooter.

avatar image NovaDrox roman_sedition · Dec 18, 2016 at 02:36 AM 0
Share

Sorry, I forgot to add that stuff...

Its a tps and its a click and fire where my courser is shooting system.

heres the file to my game

link text

battle-blocks-export.zip (413.8 kB)

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

60 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

Related Questions

Total Bullets to weapon reload? Help 1 Answer

How to bring reticles in different situations to the center of the camera? 0 Answers

How can i make my gun have two different animations 0 Answers

swapping weapons 1 Answer

How can I shoot bullets that you can aim with the crosshair? 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