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 RedOneDigitals · Jan 23, 2013 at 10:55 PM · gameobjectfpsparticlesfiresystems

How to create shoots

I want to make a ship fires and one the fire hit other object ,it will be destroyed..Can anyone help me how to define fire? is it possible to use particle system or anything??

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

Answer by Cinematronic · Jan 24, 2013 at 12:30 AM

You can start by creating a prefab for your cannonballs or whatever you wan to shot. then make a script for your ship, that instantiates the prefab, and apply force to it at button down, like rigidbody.AddForce(2, 5,0); , dunno, sort of.

EDIT: Create the prefab for the bullet. Add an empty GameObject as a child of the ship, and locate it in the tip of the barrel. Then, add this script to the ship, and then drag the objects to the respective variable. I'm doing this by memory, guess it should work:

 var bullet : GameObject;
 var bulletSpawn : GameObject;

 function Update()
 {
     if (Input.GetButtonDown("Shoot"))
     {
         var bulletShoot = Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
         bulletShoot.AddForce(2, 5,0); //use the numbers that works for you
     }
 }
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
avatar image
0

Answer by Matthew0123 · Jan 23, 2013 at 11:14 PM

Alright, I'll use a script I have already setup and will explain it to you.

 var cannonballPrefab: Rigidbody; // Finds ammo. Must be on Scene to be found.
 
 
 private var initialVelocity: float; // Starting Speed
 private var cannonMuzzle: GameObject; // The Muzzle From where it shoots from
 private var cannonBall: Rigidbody; // Place holder for the creation of the projectile
 private var interaction: String; //interaction type
 private var cannonName: String; // Returns cannon 
 function Update () {
     cannonName = GameObject.Find("First Person Controller").GetComponent(Interactions).Cannon;
     initialVelocity = 200; // Setting speed
     cannonMuzzle = GameObject.Find(cannonName + "/WholeCannon/CannonBone/Projectiles"); //Will find the ammo
     interaction = GameObject.Find("First Person Controller").GetComponent(Interactions).interaction; //Check interaction
 
  if (Input.GetKeyDown("mouse 0") && interaction == "Cannon") {
      cannonBall = Instantiate(cannonballPrefab, cannonMuzzle.transform.position, cannonMuzzle.transform.rotation); // Creates the projectile
      cannonBall.velocity = transform.TransformDirection(Vector3.forward * initialVelocity); // Add a forward motion onto it.
      cannonMuzzle.particleSystem.Play(); // Play fire animation
      var Cannon: GameObject = GameObject.Find(cannonName);
     var animationComponent: Animation = Cannon.GetComponent(Animation);
     animationComponent.animation.Play();     
  }
 }

I do not feel like trying to explain how to destroy the cannon upon impact, cause I do not feel able enough to correctly explain it to someone else like I can with this.

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

11 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

Related Questions

fps shooting in the direction of character main cam 1 Answer

Particles not activating when I want(newbie) 0 Answers

create a gameobject in front of fpsplayer 2 Answers

How can I get an object to recognize it should be on fire? 1 Answer

Activate Particles in a GM ? 0 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