OnTriggerEnter 无法正常工作

编程入门 行业动态 更新时间:2024-10-23 19:23:42
本文介绍了OnTriggerEnter 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在我为了调用死状态而制作的游戏中,我使用 box collider 来跟踪玩家是否进入特定区域,但问题是它只跟踪如果我按下键盘上的任何 a,s,dw 键.

In the game I'm making in order to call a dead state I'm using a box collider to track if the player enters in a particular zone, but the problem is that it only tracks it if I'm pressing any of the a,s,d or w keys in the keyboard.

这是代码.

OnTriggerEnter 在第 48 行被调用.

The OnTriggerEnter is called in line 48.

using UnityEngine;
using System.Collections;
public class PlayerManager : MonoBehaviour
{
    public bool Death = false;
    public bool Alive = false;
    public bool Muerto;
    public GameObject Generador;
    public GameObject StartButton;
    public CharacterMotor Motor;
    public static PlayerManager Instanse;

    // Use this for initialization
    void Start()
    {
        Instanse = this;
    }

    // Update is called once per frame
    void Update()
    {
        if (gameObject.transform.position.y <= -3.5f)
            Death = true;

        if (!Alive)
            Generador.transform.position = new Vector3(0, -0.57f, -4.98f);

        if (Death)
        {
            Generador.transform.position = new Vector3(0, -0.57f, -4.12f);
            GenerateManager.Instante.BeforeObject = GenerateManager.Instante.Spawn;
            Motor.canControl = false;
            StartButton.SetActive(true);
            CameraMovement.Instanse.CanMoveCamera = false;
            gameObject.transform.position = new Vector3(0.46f, 1.102971f, -6);
            Camera.main.transform.position = new Vector3(-0.07402526f, 12.0031f, -1.937099f);
            foreach (GameObject gm in GenerateManager.Instante.BloquesGenerados)
            {
                Destroy(gm);
            }
            GenerateManager.Instante.BloquesGenerados.Clear();
            Death = false;

        }
    }

    void OnTriggerStay(Collider other)
    {
        Debug.Log(other.tag);
        if (other.gameObject.tag == "Generador")
            GenerateManager.Instante.DoGenerate = true;
        if (other.gameObject.tag == "Muerte")
        {
            Alive = false;
            Death = true;
        }
    }
}

推荐答案

为游戏对象添加刚体组件,设置刚体组件属性 kinematic=false.

Add rigidbody component to gameobject,set rigidbody component attribute kinematic=false.

这篇关于OnTriggerEnter 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 17:33:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1176926.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   OnTriggerEnter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!