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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

My RayCast Scripts wont work

Discussion in 'Scripting' started by zcjk701, Jun 29, 2018.

  1. zcjk701

    zcjk701

    Joined:
    Jan 27, 2018
    Posts:
    5
    using UnityEngine;

    public class Bullet_Hit : MonoBehaviour
    {
    void Update()
    {
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit, 100))
    Debug.DrawLine(ray.origin, hit.point);

    {
    RaycastHit Touch;

    if (Physics.Raycast(transform.position, -Vector3.up, out hit, 100.0f))
    print("Found an object - distance: " + hit.distance);
    }

    {
    RaycastHit Colide;

    float Enemy_Health = -10f;

    }


    }
    }
     
    Last edited: Jun 29, 2018
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    More information needed.
     
  3. zcjk701

    zcjk701

    Joined:
    Jan 27, 2018
    Posts:
    5
    What am i missing i have gone through multiple tutorials and this is all they say to do
     
  4. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    Where’s the code? Looks like you messed up your copy paste, you have a class definition with the raycast declaration in it.
     
  5. zcjk701

    zcjk701

    Joined:
    Jan 27, 2018
    Posts:
    5
    I have it working now but I'm still putting in my health and damage scripts
     
  6. zcjk701

    zcjk701

    Joined:
    Jan 27, 2018
    Posts:
    5
    Now my Health scripts wont work I'm kinda new to this and trying to keep it simple

    using UnityEngine;

    public class Enemy_Health_Scrpit : MonoBehaviour {

    float Enemy_Health = 9f;

    if(Enemy_Health <0)
    {
    Destroy(GameObject);
    }
    }
     
  7. sacunha

    sacunha

    Joined:
    Apr 21, 2016
    Posts:
    148
    Do your 'enemies' objects have colliders attached?