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 yugman · Apr 22, 2012 at 09:38 PM · javascriptloadingspell

spell casting problem

ok so i try to create a basic fire spell using a mesh particle emmiter prefab that i created. it works inside the unity program but not on the built exe. At first i though it was my menu feature that was causing the problem, not the case, tried running without the menu same problem. this is the spell script i used`#pragma strict

var spell:Transform; var cooldown:float = 1.5; private var castimen : float = 0.5; var mana: int = 50;

var spellsound: AudioClip; var charges: AudioClip;

var oom: boolean = false;

function Update () { if(Input.GetButton("Fire1")&&Time.time > castimen) { if(mana > 0){ Cast(); } else{ return; } }

if(Input.GetButton("Charge")){ if (oom){ charge(); } } if(mana<=0){ oom = true; } else{ oom = false; } } function Cast(){ audio.PlayOneShot(spellsound); castimen = Time.time + cooldown;

var shot = Instantiate(spell, transform.position, Quaternion.identity); shot.rigidbody.AddForce (transform.forward * 3000); mana--; } function charge(){ audio.PlayOneShot(charges); mana = 50; }

` please help i've no idea where to go from here. thanks for your comments, what i am trying to do is instantiate the object "Spell1" as a rigid body and add force in the forward direction, however when it is built the object never even appears, also the object itself has a script attached to it that tells it to destroy itself after 3 seconds.

Comment
Add comment · Show 4
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 kolban · Apr 23, 2012 at 02:00 AM 0
Share

You post that it "doesn't work" but haven't describe what it should do when it does work nor described what you are seeing when you say it doesn't work. Code should be supplied to additionally clarify a question and not assume that your readers can read the code and intuit what it should or should not do.

avatar image Lo0NuhtiK · Apr 23, 2012 at 03:56 AM 1
Share

@kolban : Looks to me that the question is : "Why does this code run inside the editor/unity program itself, but not in the built project?" .. I don't think they were asking what's wrong with their code, just wondering what would be the reason for it working properly in one but not the other ; and then they put the code up for viewing for those that would say to the OP : "Well, whats your code? $$anonymous$$aybe there's something wrong with it. If we had that, then maybe we could tell you."

avatar image bodec · Apr 23, 2012 at 04:09 AM 0
Share

i agree with lo0n many would ask for the code even thou in this case its not needed but thanks for posting it for other to have something to look at in the adventures. not sure what to say about not working outside the editor maybe try rebuilding. check to make sure all your levels are included in your build settings.

avatar image jessee03 · Apr 23, 2012 at 05:40 AM 0
Share

If it's a mobile app use #pragma strict and if not I would remove it. It does sound more like a build issue. Check all your settings and make sure you don't have any errors after you export the project. What platform are you testing it on?

1 Reply

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

Answer by StephanK · Apr 23, 2012 at 09:02 AM

the variable spell is a Transform. Therefore if you Instantiate it you will probably get a Transform, not a GameObject. I have no idea why this works in the editor, imo it shouldn't. Try changing the type of spell to GameObject instead.

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 yugman · Apr 23, 2012 at 10:05 AM 0
Share

thanks man, changed the script to use a rigid body and every thing is working now.

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

8 People are following this question.

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

Related Questions

Save Player Health and stats 1 Answer

JavaScript Level Loading Disable A Layer 1 Answer

A question about making spells(magic) 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Save data from one scene to another? 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