Search Unity

can you help me with raycast hit collider

Discussion in 'Scripting' started by brayT, Mar 21, 2019.

  1. brayT

    brayT

    Joined:
    Jan 21, 2018
    Posts:
    65
    Hello i made a gun range and already have a target with colliders on it indicating how many points go to a player if they hit it. i also have a first person shooter that uses raycast. im not sure how to make it where if the player shoots the target that they gain a point. heres my script all i've done is made the colliders in the script.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class BulletHit : MonoBehaviour
    6. {
    7.     public Collider BullsEyeHead;
    8.     public Collider BullsEyeMiddle;
    9.     public Collider NineHead;
    10.     public Collider NineMiddle;
    11.     public Collider EightHead;
    12.     public Collider EightMiddle;
    13.     public Collider SevenMiddle;
    14.     public Collider SixMiddle;
    15.     public Collider Zero;
    16.     public Collider Neck;
    17.  
    18.     // Start is called before the first frame update
    19.     void Start()
    20.     {
    21.        
    22.     }
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.        
    28.     }
    29. }
    it be nice if i got some help on this problem.
     
  2. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Well if you have those colliders, your player shooting script should know when raycasting, what the colliders name is. You can then just call a function and check for that name/collider and do your stuff there.