Raycast() 공개 메소드

public Raycast ( Vector3 targetPosition, NavMeshHit &hit ) : bool
targetPosition Vector3
hit NavMeshHit
리턴 bool
 static public int Raycast(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshAgent self = (UnityEngine.AI.NavMeshAgent)checkSelf(l);
         UnityEngine.Vector3         a1;
         checkType(l, 2, out a1);
         UnityEngine.AI.NavMeshHit a2;
         var ret = self.Raycast(a1, out a2);
         pushValue(l, true);
         pushValue(l, ret);
         pushValue(l, a2);
         return(3);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int Raycast(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.AI.NavMeshAgent obj  = (UnityEngine.AI.NavMeshAgent)ToLua.CheckObject(L, 1, typeof(UnityEngine.AI.NavMeshAgent));
         UnityEngine.Vector3         arg0 = ToLua.ToVector3(L, 2);
         UnityEngine.AI.NavMeshHit   arg1;
         bool o = obj.Raycast(arg0, out arg1);
         LuaDLL.lua_pushboolean(L, o);
         ToLua.PushValue(L, arg1);
         return(2);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #3
0
    void Update()
    {
        float dist = Vector3.Distance(player.position, enemy.position);

        if (!agent.pathPending && agent.remainingDistance < 3f)
        {
            GoToNextPoint();
        }
        NavMeshHit hit;

        if (!agent.Raycast(player.position, out hit))
        {
            playerVisible = true;
        }
        else
        {
            playerVisible = false;
        }

        if (playerVisible && dist < breakDistance)
        {
            breakPatrol = true;
        }
        if (Input.GetButtonDown("Fire1") && dist < breakDistance)
        {
            breakPatrol = true;
        }
        if (enemyHealth.beingShot)
        {
            breakPatrol = true;
        }

        if (breakPatrol)
        {
            enemyMovement.enabled = true;
            patrol.enabled        = false;
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (HP <= 0)
        {
            nav.isStopped = true;
            Destroy(gameObject, 3f);
            return;
        }
        NavMeshHit hit;
        Vector3    targetDir = Player.position - transform.position;

        if (Vector3.Angle((Player.position - transform.position), Vector3.forward) < 20f && Time.time > fireuse && !nav.Raycast(Player.position, out hit))
        {
            Instantiate(capsule, spawn.transform.position, transform.rotation, transform);
            fireuse = Time.time + firetime;
        }
        else
        {
            nav.SetDestination(Player.position);
        }
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        if (HP <= 0)
        {
            anim.SetTrigger("dead");
            anim.SetBool("walking", false);
            anim.SetBool("suspicious", false);
            anim.SetBool("detected", false);
            nav.isStopped = true;
            Destroy(gameObject, 3f);
            return;
        }
        NavMeshHit hit;

        if (!isFocused)
        {
            foreach (GameObject player in Players)
            {
                if (player.activeSelf)
                {
                    if (Vector3.Angle(player.transform.position - transform.position, transform.forward) < _fov && (player.transform.position - transform.position).magnitude < 3f &&
                        !nav.Raycast(player.transform.position, out hit) || player.GetComponent <AudioSource>().minDistance > (player.transform.position - transform.position).magnitude)
                    {
                        Player    = player.transform;
                        audio     = player.GetComponent <AudioSource>();
                        isFocused = true;
                        break;
                    }
                    if ((player.transform.position - transform.position).magnitude < (Player.position - transform.position).magnitude)
                    {
                        Player = player.transform;
                        audio  = player.GetComponent <AudioSource>();
                    }
                }
            }
        }
        Vector3 targetDir = Player.position - transform.position;
        float   angle     = Vector3.Angle(targetDir, transform.forward);

        if (hint || ((targetDir).magnitude < 3f && !nav.Raycast(Player.position, out hit) && angle < _fov || audio.minDistance > targetDir.magnitude))
        {
            hint          = false;
            isFocused     = true;
            _time         = 0f;
            nav.isStopped = false;
            anim.SetBool("walking", false);
            anim.SetBool("suspicious", false);
            anim.SetBool("detected", true);
            nav.SetDestination(Player.position);
        }
        else
        {
            isFocused = false;
            if (anim.GetBool("detected") && (Player.position - transform.position).magnitude < 1f)
            {
                _time         = 0f;
                nav.isStopped = false;
                anim.SetBool("walking", false);
                anim.SetBool("suspicious", false);
                anim.SetBool("detected", true);
                nav.SetDestination(Player.position);
                isFocused = true;
            }
            else
            {
                if (audio.maxDistance > targetDir.magnitude)
                {
                    anim.SetBool("suspicious", true);
                    _fov = 90f;
                }
                if ((nav.destination - transform.position).magnitude <= 0.2f)
                {
                    anim.SetBool("detected", false);
                    if (anim.GetBool("walking"))
                    {
                        if (_time > 3f)
                        {
                            anim.SetBool("suspicious", false);
                            _fov  = 60f;
                            _time = 0f;
                        }
                        anim.SetBool("walking", false);
                        nav.isStopped      = true;
                        transform.rotation = initialDir;
                    }
                    else
                    {
                        anim.SetBool("suspicious", true);
                        if (_time > 3f)
                        {
                            anim.SetBool("suspicious", false);
                            anim.SetBool("walking", true);
                            nav.SetDestination(initialPos);
                            _time = 0f;
                        }
                    }
                    if (anim.GetBool("suspicious"))
                    {
                        _time += Time.deltaTime;
                    }
                }
            }
        }
        if (anim.GetBool("detected") && (Player.position - transform.position).magnitude < 0.45f && Time.time > fireuse)
        {
            fireuse = Time.time + firetime;
            Player.GetComponent <PSNetwork>().Damage(damage);
        }
        if (Player.GetComponent <PSNetwork>().isdead)
        {
            Players   = GameObject.FindGameObjectsWithTag("Player");
            isFocused = false;
            Player    = Players[0].transform;
        }
    }