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 /
avatar image
1
Question by Dimwood2011 · Aug 27, 2015 at 12:21 PM · collision

Detect collision only once when collider hits 2 objects at same time

I have a dart game that has a OnCollisionEnter() script on every collider. example single20 has a collider with script that tells my ScoreManager script to change text from 501subtract 20 which equals 481 which does as it should.Triple 20 has its own script that subtracts 60 as it should.....Double 20 has its own script that subtracts 40 as it should.I have this on every number and bullseye.

The problem is that the dart I am using has a Sphere collider which hits 2 colliders at the same time on the edges so it scores from 2 colliders at the same time when i only want to score from one collider at a time.I know about Layers, but the colliders I think have to be in the same Layer unless I am think too hard about Layers.

this script subtracts for Triple 20

 using UnityEngine;
 using System.Collections;
 
 public class subScoreTrip20 : MonoBehaviour 
 {
     public int scoreValue;
     public bool unhit = true;//
     public Transform prefab;
 
     void Start () 
     {
 
     }
     void OnCollisionEnter(Collision other) 
     {
         if(other.collider.tag == ("dart"))//&& unhit)/////////////
         {
             Instantiate (prefab, transform.position, transform.rotation);
             //CameraShake script;
             //script = Object.GetComponent<CameraShake>();
             //script.enabled = true;
             ScoreManager.score -= scoreValue = 60;
             audio.Play ();
             other.rigidbody.isKinematic = true;
         }
         //unhit = false;///////
 
         //Destroy(gameObject, 1);///////
 
     }
 }

and the ScoreManager script

 using UnityEngine;
 using UnityEngine.UI; // This is the call for the new UI, this MUST be in here for this to work.
 using System.Collections;
 //[RequireComponent(typeof(AudioSource))]
 public class ScoreManager : MonoBehaviour
 {
     public static int score = 501;        // The player's score.
     public static int oldScore = 501;
 
     Text text;                      // Reference to the Text component.
     
     
     void Awake ()
     {
         // Set up the reference.
         text = GetComponent <Text> ();
         
         // Reset the score.
         score = 501;
 
     }
     
     
     void Update ()
     {
 
         // Set the displayed text to be the word "Score" followed by the score value.
         if(score < 0 || score == 1)
         {
             //AudioSource audio = GetComponent<AudioSource>();
             audio.Play ();
             score = oldScore;
 
 
         }
         else
         {
             oldScore = score;
         }
 
 
         text.text = " " + score;
         oldScore = score;
         if(score == 0)
         {
             //audio.Play ();
             Debug.Log ("You Win");
             Application.LoadLevel("L2");
         }
 
     }
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by oldcollins · Oct 27, 2016 at 05:29 PM

if you add something like this to your dart(Sphere collider). It'll make the dart stick to the one it has hit

 function OnCollisionEnter(col : Collision)
 {
   var Dart = gameObject.AddComponent(FixedJoint);
     Dart.connectedBody = col.rigidbody;    
     print("Darthit");
 }`

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Emitting Particles on Collision 0 Answers

How to detect when an object goes past (so it looks like it touches) a UI element. 1 Answer

How to prevent Collider from shaking when colliding with another Collider? 2 Answers

Collsion without ririgibody 1 Answer

Rigidbody MoveTo considering collisions 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