OnTriggerEnter not working when placed inside Update()

发布时间:2026-01-18 23:35

'follow-up'用'update'或'reply'表示 #生活技巧# #职场沟通技巧# #商务英语#

I'm making a scanner that scans the "world" (like a 10 x 10 space), and I'm trying to sense a GameObject called pointer.

They both have colliders, they both have triggers, and the scanner has a rigidbody. I have tried the OnTriggerEnter method outside of the update, and it worked, but as soon as I put it inside of Update, it breaks.

I don't have to worry about being specific on what the scanner is detecting, because those two are the only ones with a collider.

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Scan : MonoBehaviour { public int worldHeight; public int worldWidth; public bool sensed; public bool spaceBar = false; void Update() { if (Input.GetKeyDown("space") && spaceBar == false) { spaceBar = true; sensed = false; //brings scanner to top left corner of world transform.position = new Vector3(worldWidth / 2 * -0.64f + 0.32f, worldHeight / 2 * 0.64f + 0.32f, -1); for (int sizey = 0; sizey < worldHeight; sizey++) { if (sensed == false) { //shifts scanner down transform.position = new Vector3(worldWidth / 2 * -0.64f - 0.32f, transform.position.y, -1); transform.position = transform.position - new Vector3(0, 0.64f); for (int sizex = 0; sizex < worldWidth; sizex++) { if (sensed == false) { //shifts scanner right transform.position = transform.position + new Vector3(0.64f, 0); void OnCollisionEnter2D(Collision2D grid) { //not working ;-; sensed = true; } } } } } } else { spaceBar = false; } } }

网址:OnTriggerEnter not working when placed inside Update() https://klqsh.com/news/view/321212

相关内容

OnTriggerEnter works...sometimes
XPUIPC / XPWideClient update for
Mod Page Permissions Update
Working essential Mod List Updated 4/27 V11
Best LMS Software to Use When Working Remotely: Top 7 Options for Your Team
Mouse stickiness change with multiple monitors after Windows 8.1 Update 1: Bug or feature?
Steam Discovery Update
“Within” and “in” when referring to time
Lost Your PM Kisan Registration Number? Know It Instantly Using Aadhaar Or Mobile – Full Guide Inside!
New Edinburgh Park Fieldhouse – New Edinburgh

随便看看