Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bullet handshake

Discussion in 'Scripting' started by Jason_Hipkins, Aug 16, 2016.

  1. Jason_Hipkins

    Jason_Hipkins

    Joined:
    Dec 23, 2015
    Posts:
    57
    Hello, only been using Unity for a few days so far, so please let me know if this question has already been answered and I just didn't know how to word it for the search engine.

    I have 2 scripts, one is a gun, and one is a target. The target has a drop down Enum list to tell what material the target is, like metal. What I want is for the gun script to be able to look at the target script, and find out what the material is. Is there a way for the one script to pull that information based on a raycast collider, or if not, how would I push that information back to the gun? I can post actual code, but I'm sure it doesn't read very well since I'm still learning this stuff. Many thanks.
     
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    I think you're looking for script communication. That's done through GetComponent.


     
  3. Jason_Hipkins

    Jason_Hipkins

    Joined:
    Dec 23, 2015
    Posts:
    57
    Thanks, know it's probably simple but it's stretching my brain quite a bit. Looks like what I'm looking for, thanks
     
    SubZeroGaming likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    This is what's beautiful about Unity and component model architecture! Enjoy the brain stretch! Revel in it! I have had to buy three new skulls already since I started using Unity.
     
  5. Jason_Hipkins

    Jason_Hipkins

    Joined:
    Dec 23, 2015
    Posts:
    57
    3 hours lost due to errant semicolon
     
  6. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    Those'll get ya.
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    At this stage you might find it worthwhile, or at least satisfying, to sternly discipline that errant semicolon, if for no other reason than to serve as an example to all the other potentially miscreant punctuation marks.
     
    Vedrit likes this.