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 lolage · Jan 31, 2011 at 09:26 PM · shootingshoot

Shootin Worminator Like Game

Hi guys i am making a game similar to worminator. However my shooting script doesnt work in that my character doesnt even fire the bullet although movement works, can you have a look at it and see whats wrong.

var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab:Transform;
function Update ()
{
    var controller : CharacterController = GetComponent(CharacterController);
    transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
    var forward = transform.TransformDirection(Vector3.forward);
    var curSpeed = speed * Input.GetAxis ("Vertical");
    controller.SimpleMove(forward * curSpeed);
    var Bullet : Transform;
    function (
    (Input.GetButtonDown("Jump"))
    {
        Instantiate(Bullet,transform.position,Quaternion.identity);
        Bullet.rigidbody.AddForce(transform.forward * 1000);
    }    
}

Thanks

Comment
Add comment · Show 1
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 Mike 3 · Feb 01, 2011 at 02:54 AM 0
Share

I added the code into a code block to make it readable - For next time, please select the code after you've pasted it, and click the button with 0's and 1's on it (like 110101, i forget exactly)

3 Replies

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

Answer by FLASHDENMARK · Feb 01, 2011 at 06:01 PM

Mabye like so:

var speed = 3.0; var rotateSpeed = 3.0; var Bullet : Transform;

 function Update ()
 {
     var controller : CharacterController = GetComponent(CharacterController);
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
     var forward = transform.TransformDirection(Vector3.forward);
     var curSpeed = speed * Input.GetAxis ("Vertical");
     controller.SimpleMove(forward * curSpeed);

     if(Input.GetButtonDown("Fire1"))
     {
     Bullet = Instantiate(Bullet,transform.position,Quaternion.identity);
     Bullet.rigidbody.AddForce(transform.forward * 1000);    
     }

 }

Good old TornadoTwins, he is awesome ;)

Comment
Add comment · Show 4 · 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 lolage · Feb 01, 2011 at 06:23 PM 0
Share

ok it works apart from it says the thing you want ot instatiate is nul?

avatar image lolage · Feb 01, 2011 at 06:25 PM 0
Share

also do i need to put where it actually forms?

avatar image FLASHDENMARK · Feb 01, 2011 at 07:27 PM 0
Share

I have found the error. At the end of the script above the "if statement" There you declared a variable(var) but you had also declared it at the top. I assume that Unity did not like that. I will update the script :)

avatar image Mike 3 · Feb 02, 2011 at 01:29 AM 0
Share

That'll cause null ref exceptions every time after the first instantiation

avatar image
1

Answer by Mike 3 · Feb 01, 2011 at 02:52 AM

This should fix it:

var Bullet : Transform;
if (Input.GetButtonDown("Jump"))
{
    Bullet = Instantiate(bullitPrefab,transform.position,Quaternion.identity);
    Bullet.rigidbody.AddForce(transform.forward * 1000);
}

First change is that it needs to use if, not function, to check if the key is down

Second is that you need to assign the Instantiate to the Bullet prefab so you can use it after

Third is that you need to Instantiate bullitPrefab, not Bullet (which is completely empty still)

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 lolage · Feb 01, 2011 at 05:47 PM 0
Share

It doesnt seem to work :( firstly i see that it says expectin } found " on 17,1. Secondly do i need to change the word bullit prefab to my bullet and thirdly do i attach it to the actual character?

avatar image lolage · Feb 01, 2011 at 05:59 PM 0
Share

ok so i filled the bullit prefab and thats ok, all i need to know now is why it wont actually run because of the "expecting } found " on 17,1."

avatar image Mike 3 · Feb 02, 2011 at 01:30 AM 0
Share

You may want to edit your question with the entire code. Replacing from var Bullet : Transform up until the first } with my code should have fixed it

avatar image
0

Answer by lolage · Feb 01, 2011 at 05:27 PM

It doesnt seem to work :( firstly i see that it says expectin } found " on 17,1. Secondly do i need to change the word bullit prefab to my bullet and thirdly do i attach it to the actual character?

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

No one has followed this question yet.

Related Questions

Shoot Script Help 1 Answer

Hey can anyone help with a shooting script??? 0 Answers

simple shooting script help 3 Answers

Trouble with selective projectile script 0 Answers

Shooter in iOS and a visible Aim line before shooting 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