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 Hannandh · Dec 20, 2011 at 12:42 AM · errorgun

Problem doing a script.

This is the error message I get.

Assets/Scipt0/Gun.js(22,20): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Transform, UnityEngine.Vector3, UnityEngine.Vector3)' was found.

This is my script.

var sparks : Transform;

var ammo : int = 100;

var fireRate : float = 0.2;

private var nextFire : float = 0.0;

function Update () {

 if(Input.Getbutton("Fire1")){
 
     if(Time.time > nextFire){
 
         nextFire = Time.time + fireRate;
         fire();
         
     }
 }

}

function fire(){

 var range = Mathf.Infinity;
 
 var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 
 var hit : RaycastHit;
 
 if (Physics.Raycast (ray, hit, range)) {
 
     Instantiate(sparks, hit.point, hit.normal); 
 
 }

}

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 Lo0NuhtiK · Dec 20, 2011 at 12:49 AM 0
Share

Old habits die hard, so, might as well start off doing things right and get your script formatted correctly in the code box so we can read it.

avatar image Hannandh · Dec 20, 2011 at 01:24 AM 0
Share

It looks right when I go in to edit it, so I don't know why it comes out like this, shouldn't be that hard to decipher...

avatar image Hannandh · Dec 20, 2011 at 01:43 AM 1
Share

No problem, I'll try to make it easier to read now, I completely understand what you mean, I'm asking for help so there is no need to make it more difficult on who is helping me.

2 Replies

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

Answer by Zergling103 · Dec 20, 2011 at 01:56 AM

Here:

 var sparks : Transform;
 var ammo : int = 100;
 var fireRate : float = 0.2;
 private var nextFire : float = 0.0;
 
 function Update () {
     if(Input.Getbutton("Fire1") && Time.time > nextFire) {
          nextFire = Time.time + fireRate;
          fire();
     }
 }
 
 function fire() {
     var range = Mathf.Infinity;
     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     var hit : RaycastHit;

     if (Physics.Raycast (ray, hit, range)) {
 // --------------------------------------------------------------
         Instantiate(sparks, hit.point, Quaternion.LookRotation(hit.normal)); 
 // --------------------------------------------------------------
     }
 }

:)

Instantiate requres a special rotation structure called a Quaternion be used to describe it's starting rotation. Quaternion.LookRotation() does basically what you intended by figuring out what rotation is requried to look at a point in space when standing at (0,0,0).

Comment
Add comment · Show 5 · 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 Hannandh · Dec 20, 2011 at 02:00 AM 1
Share

Thanks dude, I'll make sure not to make the mistake again :P

avatar image Zergling103 · Dec 20, 2011 at 02:01 AM 0
Share

Give me a +1 please :)

avatar image Hannandh · Dec 20, 2011 at 02:07 AM 2
Share

How do I do that? Sorry, I only made this Profile to ask this certain question, I'm new to this, bare with me and I'll give you the +1 if you tell me how, god, I'm such a noob. -_-;

avatar image Zergling103 · Dec 20, 2011 at 02:09 AM 0
Share

See the thumb up icon by my answer? :) That.

Don't worry about looking like a noob. xD

avatar image Lo0NuhtiK · Dec 20, 2011 at 02:10 AM 1
Share

lol ... I'll give you one also

avatar image
0

Answer by save · Dec 20, 2011 at 12:51 AM

Instantiate takes three parameters, the object, the position and the rotation. The rotation has to be a quaternion. Is there a reason you're using the normal from hit? Otherwise switch it to Quaternion.identity or the desired Quaternion.Euler(x, y, z).

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 Hannandh · Dec 20, 2011 at 01:25 AM 0
Share

Sorry, I really don't understand this, I'm just learning how to use Unity, I'm not too familiar with scripting or anything.

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Error line 22! Help. i dont know why? 1 Answer

Wierd error messages concerning audio play and pause? 1 Answer

Make player unable to shoot when reloading 3 Answers

Error CS1502 Help! 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