Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jul 07, 2018 at 12:44 PM by wilsonshw for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by wilsonshw · Jul 07, 2018 at 10:45 AM · unityeditor

Inconsistent Sphere Collider Behavior

Hello,

I'm making a game where there are enemies with their (sphere) collider disabled by default. When the player taps and drags on a character to command it to attack the enemy, I want the enemy collider to be enabled (for raycasting to this enemy target), and then disabled again when the player lifts his finger (OnMouseButtonUp). This is to prevent enemies from obstructing the main characters when selecting them. The code below works:

  if (character_controller.didDrag && character_controller.whichChar != 1)  //checks that the correct characters are chosen and player drags on screen
         {
             if (!transform.Find("raycastColl").GetComponent<SphereCollider>().enabled)
                 transform.Find("raycastColl").GetComponent<SphereCollider>().enabled = true;
         }
         else
         {
             if (transform.Find("raycastColl").GetComponent<SphereCollider>().enabled)
                 transform.Find("raycastColl").GetComponent<SphereCollider>().enabled = false;
         }

Here are some problems:

1) I do not see the 'Sphere Collider' checkbox being triggered at all (appears to be always off). I assigned a dummy boolean to check in the inspector, and the dummy showed that it should be triggered:alt text

2) Even though it appears to not be enabled, characters ARE able to target the enemies, provided the enemies are placed on the scene beforehand, which brings me to the next point;

3) When I instantiate enemies using a prefab, point 1) stands true, but for point 2), characters can NOT target the enemies;

These have me completely stumped. What makes it even more confusing is I have the exact same code on a boss enemy which works perfectly, with the collider triggered on and off (and indicated properly) accordingly. I'm using Unity 2017.3.1p3. Help? Thanks in advance.

Edit: SOLVED - Apparently, moving the above block of code into LateUpdate() fixed the problem.

tt1.png (111.4 kB)
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

86 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 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 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 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 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

Unity opens but displays nothing. How can i fix this? 0 Answers

What are the system requirements for previous versions of Unity? 1 Answer

How to install Unity Editor On CentOs 7(LINUX)? 1 Answer

Unity application automation,How to identify the gameObjects when application is running in Hololens via Holographic Remoting 0 Answers

System.IO.Ports missing for Unity with .NET 4.x 3 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