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 Miziziziz · Sep 28, 2013 at 07:47 PM · functioncalling

why is part of my script getting called as if it was in the Start function?

so this is the script, it's the basic explosion script from the Unity scripting reference. the problem is that as soon as the game starts, blocks go flying; it completely ignores whether I've pressed the button down or not.

 using UnityEngine;
 using System.Collections;
 
 public class Explode : MonoBehaviour 
 {
 
 
       public float radius = 6.0F;
     public float power = 10.0F;
 
     void Update() 
     {
         if(Input.GetKeyDown (KeyCode.E))
         {
             Debug.Log ("called");
             Vector3 explosionPos = transform.position;
             Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
             foreach (Collider hit in colliders) {
             if (!hit)
             
             if (hit.rigidbody)
                 hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0F);
             }
         }
     }
 
 }
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 Miziziziz · Sep 28, 2013 at 08:34 PM 0
Share

sorry, I meant flying as in propelled by an explosion. I doubt it, nothing happens if the explosion script isn't in place. strangely, the explosion also does not work if IsTrigger is enabled on the collider

and no, the debug log does not output

avatar image Miziziziz · Sep 28, 2013 at 08:38 PM 0
Share

oh ha, that would explain a few things. I just realized the collider was what was making the rigidbodies move. Now it's just an issue of the explosion script not working... well, thanks

avatar image justinpatterson · Sep 28, 2013 at 10:05 PM 0
Share

try commenting out just the line that causes the actual explosion, and see if anything still happens?

avatar image Miziziziz · Sep 28, 2013 at 10:33 PM 0
Share

deactivating the script itself still causes it. it's definitely a collider problem.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by gardian06 · Sep 28, 2013 at 08:02 PM

flying how?

is it possible that you somehow put rigidbodies inside of one another, and they are simply responding to the collision?

does your debug log get outputted?

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 Entairex1 · Sep 28, 2013 at 09:58 PM

Hmm you have some strange spacing in your code

 using UnityEngine;
 using System.Collections;
 public class Explode : MonoBehaviour
 {
     public float radius = 6.0f;
     public float power = 10.0f;
     void Update()
     {
         if(Input.GetKeyDown(KeyCode.E))
         {
             Debug.Log("called");
             Vector3 explosionPos = transform.position;
             Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
             foreach(Collider hit in colliders){
                 if (!hit)
                     if(hit.rigidbody)
                         hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0F);
             }
         }
     }
 }

This should be working, if it's not, then it's probably because you have another script causing this problem.

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 Miziziziz · Sep 28, 2013 at 10:42 PM 0
Share

yeah the force just isn't applying for some reason. I guess I'll just have to ask another question on Unity Answers... thanks for the help, though

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

18 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

Related Questions

Pre-Built versus Custom functions 1 Answer

Calling functions from a class - Curious issue 1 Answer

Calling a function in another script. 1 Answer

Can I do recursion in unity3d compiler using javascript? 1 Answer

How do you call a function with a button? Unity 5 UI 8 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