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
0
Question by glennwjason · Jan 20, 2019 at 11:23 AM · unity 5raycastlerp

Object detect my light RayCast and activating Lerp

I am trying to get make a script that will detect when my light that has a set range of 7 it's raycast hits a few different objects. Once the object detects the ray it will start my lerp(colors are set in inspector from alpha(0)-alpha(1)). I have set up my lerp and checked if it runs in the update function(it does). My goal is now to only activate the lerp now once the ray hits the object the lerp is on.

I have tried looking through the documentation (ray, raycast, raycasthit, etc), I saw about having to change layers as well which my next course of action was to have all other objects on layer IgnoreRayCast just not sure if thats the best or most efficient way, also I tried somethings from (https://www.reddit.com/r/Unity3D/comments/6ryx76/raycast_for_activating_objects/). I am very new to unity and have only been programming for a few months, I am having a hard time even understanding how to read the documentation properly to execute what is being relayed. Any help would be really appreciated, not to sound too ignorant but layman's terms if possible?

(script for object going through lerp)

 public class enumLight : MonoBehaviour
 {
     public float speed = 1;
     public Color startColor;
     public Color endColor;
     float startTime;
     // Start is called before the first frame update
 
     void Start()
     {
         startTime = Time.time;
     }
 
     // Update is called once per frame
     void Update()
     {
         RaycastHit hit;
         float t = (Time.time - startTime) * speed;
         GetComponent<Renderer>().material.color = Color.Lerp(startColor, endColor, t);
         //Debug.Log(Color.Lerp(startColor, endColor, t));
         //Debug.Log(hit.transform.name);
 
         //hitByray();
     }
     void hitByray()
     {
         Debug.Log("I was hit");
     }
 }


(script from my light that the raycast is on)

 //hold the camera
     public Camera lightRay;
     //camera range for raycast
     public float lightRange = 7f;
     //reference the puzzle
     public GameObject LightBox;
     LightPuzzle lightPuzzle;
 
 
 
     // Start is called before the first frame update
     void Start()
     {
         lightPuzzle = LightBox.GetComponent<LightPuzzle>();
 
     }
 
     // Update is called once per frame
     void Update()
     {
         shoot();
 
     }
 
     void shoot()
     {
         RaycastHit hit;
 
         if (Physics.Raycast(transform.position, -Vector3.up, out hit))
         {
             hit.transform.SendMessage("hitByRay");
         }
 
     if (Physics.Raycast(lightRay.transform.position, lightRay.transform.forward, out hit, lightRange))
     {
        Debug.Log(hit.transform.name);
         if (hit.distance < lightRange)
         {
 
         }
     }
 }


in summary I want my object that has the lerp to detect my light that has the raycast on it to activate the lerp that I have in place.

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

0 Replies

· Add your reply
  • Sort: 

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

224 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help rotating the inside of a cube correctly (lerp gets me mid-way there) 2 Answers

Control time transition between colors 1 Answer

Unity android screen resolution 1 Answer

Click/Touch on Different part of sprite detected ? 0 Answers

Why is my object not rotating smoothly ? C# 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