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 /
  • Help Room /
avatar image
0
Question by Cameron Murtagh · Mar 03, 2016 at 02:02 PM · convertjava to c#

Can someone help me please?

Follow Player when in sight script!

Hello everyone I have this javascript...

 import UnityEngine.SceneManagement;
 
 
 public var fieldOfViewAngle : float = 150f;             // Number of degrees, centred on forward, for the enemy see.
 public var playerInSight : boolean;                     // Whether or not the player is currently sighted.
 
 private var nav : NavMeshAgent;                         // Reference to the NavMeshAgent component.
 private var player : GameObject;                        // Reference to the player.
 
 
 function Awake ()
 {
     // Setting up the references.
     nav = GetComponent(NavMeshAgent);
     player = GameObject.FindGameObjectWithTag("Player");
     playerInSight = false;
 }
 
 
 function Update ()
 {
     if (playerInSight)
     {
       nav.SetDestination(player.transform.position);
     }
 }
 
 
 function OnTriggerStay (other : Collider)
     {
         
         // If the player has entered the trigger sphere...
         if(other.gameObject.tag == "Player")
         {
             // By default the player is not in sight.
             
            
             // Create a vector from the enemy to the player and store the angle between it and forward.
             var direction : Vector3 = other.transform.position - transform.position;
             var angle : float = Vector3.Angle(direction, transform.forward);
             
             // If the angle between forward and where the player is, is less than half the angle of view...
             if(angle < fieldOfViewAngle * 0.5f)
             {
                 var hit : RaycastHit;
                 //Debug.Log("intrigger");
                 // ... and if a raycast towards the player hits something...
                 if(Physics.Linecast(transform.position , other.transform.position)!=true)
                 {                                     
                         // ... the player is in sight.
                         playerInSight = true;
                        if (Vector3.Distance(transform.position , other.transform.position)<=1.5)
                        {
                                SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);
                        }
                    
                 }
             }
         }
     }
 
 
     function OnTriggerExit (other : Collider)
         {
             // If the player leaves the trigger zone...
             if(other.GetComponent.<Collider>().gameObject.tag == "Player")
                 // ... the player is not in sight.
                 Invoke("LooseSightDelayed",1);
                 
         }
 
         function LooseSightDelayed()
         {
             playerInSight = false;
         }
 
        /* function CalculatePathLength (targetPosition : Vector3)
             {
                 // Create a path and set it based on a target position.
                 var path : NavMeshPath = new NavMeshPath();
                 if(nav.enabled)
                     nav.CalculatePath(targetPosition, path);
                 Debug.Log("triggered");
     
                 // Create an array of points which is the length of the number of corners in the path + 2.
                 var allWayPoints : Vector3[] = new Vector3[path.corners.Length + 2];
     
                 // The first point is the enemy's position.
                 allWayPoints[0] = transform.position;
     
                 // The last point is the target position.
                 allWayPoints[allWayPoints.Length - 1] = targetPosition;
     
                 // The points inbetween are the corners of the path.
                 for(var i = 0; i < path.corners.Length; i++)
                 {
                     allWayPoints[i + 1] = path.corners[i];
                 }
     
                 // Create a float to store the path length that is by default 0.
                 var pathLength : float = 0;
                 // Increment the path length by an amount equal to the distance between each waypoint and the next.
                 for(var j = 0; j < allWayPoints.Length - 1; j++)
                 {
                     pathLength += Vector3.Distance(allWayPoints[j], allWayPoints[j + 1]);
                 }
     
                 return pathLength;
             }*/

and I am not too experienced with this particular type of script but I got help and made it work! I am making a game using c# and want all the scripts to be the same type so I was wondering is there anyone out there that would take the time to convert this script into c# for me please and thank you! I would really appreciate it!!!

-Cameron-

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

48 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

Related Questions

Convert Java to C# 2 Answers

change my code from java to c# 1 Answer

JavaScript to C# 1 Answer

Heightmap From Texture - Script Converter 2 Answers

Convert Java to 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