Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 HarleysZoonBox · Oct 17, 2013 at 05:20 AM · functionraycasthitif statementelse

what code should i be using if im only wanting a function to happen if a raycast does not return a hit

Im Writting a Script that will generate a list of connect waypoints but the only thing is im stuck with the last peice of code...

this is my code



 #pragma strict

 @script ExecuteInEditMode()
 
 
 /************************************************************************************************************/
 // Simple Waypoint Script.
 // Author: Harley Urquhart
 // Version: 1
 /************************************************************************************************************/
 //Notes
 //This Requires that at least one other waypoint is included as a link
 //Behaviours can then be made 
 /************************************************************************************************************/
 //Variables
 var Links : Transform[];
 /************************************************************************************************************/
 function Awake(){
     //test for errors
     if (Links.Length <1){
         //display an error and the name of the waypoint
         Debug.LogError("Please assign at least one object to the array of waypoints in the editor for: " + gameObject.name);
     }
     if(gameObject.CompareTag("Untagged")){
         //    Set the Tag Immediately if the player forgot to tag the Waypoint Prefab
         gameObject.tag = "Waypoint";
     }
 }
 
 function Start () {
     //make the object invisible
     renderer.enabled = false;
     //turn off collisions
     collider.enabled = false;
 }
 
 function Update(){
     // draw a ray to visualise the path between Two way points(minimum)
     // create a forloop
     
     //instead of manually adding linked waypoints 
     //find waypoins that are not obscured by any colliders 
     //then link them together by adding that waypoint to the links array
     
     // Find all game objects with tag Waypoint
     var Waypoints : GameObject[];//array of all tagged Gameobjects
     Waypoints = GameObject.FindGameObjectsWithTag("Waypoint"); 
     var position = transform.position; //
     //find waypoints that are not blocked by a collider.
     for (var waypoint : GameObject in Waypoints)  { 
         //cast out a ray
         var hit : RaycastHit;
         if (Physics.Raycast (position, waypoint.transform.position, hit)) {
             
         }
     }    
     
     for (var x = 0; x < Links.Length;x++){
         //iterate through all the coonected waypoints and cast rays out
         Debug.DrawLine(transform.position, Links[x].position,Color.red);
     }
     
 }
 
 function OnDrawGizmos () {
     Gizmos.DrawIcon (transform.position, "Light Gizmo.tiff", true);
 }



i just need help at line 53 to inset the correct code here

Comment
Add comment · Show 1
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
avatar image HarleysZoonBox · Oct 17, 2013 at 05:23 AM 0
Share

please note this is an addition to a script that will then be a part of a Waypoint Navigation system i will add to the asset store later on.

This Script will be part of a small package later on...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wilgieseler · Oct 17, 2013 at 05:34 AM

Seems like a simple if/else statement to me, at least in this particular script.

     if (Physics.Raycast (position, waypoint.transform.position, hit)) {
       // raycast did hit
     }
     else {
       // raycast didn't hit
     }
Comment
Add comment · Show 2 · Share
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
avatar image HarleysZoonBox · Oct 17, 2013 at 09:23 AM 0
Share

the only problem is no matter what i have checked it against so far the else wont return or i get both happening.. ill try to see if this works and ill be right back

avatar image meat5000 ♦ · Oct 17, 2013 at 09:42 AM 0
Share

From the scripting reference

Returns bool True when the ray intersects any collider, otherwise false.

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

16 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

Related Questions

If statement is being ignored and else is run instead 1 Answer

'else' won't work in an if statement 1 Answer

Using "collider.name" vaule to determine next move? C# 1 Answer

Need help with If/else statement. 1 Answer

Faulty use of else within a function? 2 Answers


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