Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Raycast Interaction Script C#

Discussion in 'Scripting' started by CarbonNanoRob, Nov 13, 2014.

  1. CarbonNanoRob

    CarbonNanoRob

    Joined:
    Nov 6, 2014
    Posts:
    1
    using UnityEngine;
    using System.Collections;
    public class Interaction : MonoBehaviour
    {
    void Update()​
    {
    RaycastHit hit;
    if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward),out hit, 2))
    {
    if (hit.collider.tag.Equals("YourObjectTagHere"))
    {
    Debug.Log("Interact");
    if (Input.GetKeyDown(KeyCode.E))
    {
    hit.collider.SendMessageUpwards("YourScriptFunctionHere");​
    }​
    }​
    }​
    }​
    }
     
  2. arthur_fukushima

    arthur_fukushima

    Joined:
    Nov 12, 2014
    Posts:
    28
    Is this a question?
     
  3. zDemonhunter99

    zDemonhunter99

    Joined:
    Apr 23, 2014
    Posts:
    478
  4. Cpt Chuckles

    Cpt Chuckles

    Joined:
    Dec 31, 2012
    Posts:
    86
    i like turtles
     
  5. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    Code (CSharp):
    1. What is your point?
     
  6. Blakemprods

    Blakemprods

    Joined:
    Feb 7, 2019
    Posts:
    5
    Thanks, this is just what I needed.
     
  7. anthonyfuentez06

    anthonyfuentez06

    Joined:
    Feb 4, 2020
    Posts:
    1
    thanks i guess
     
unityunity