- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个从玩家发射的射弹预制件,当它与“边界”碰撞时,它应该摧毁自己,当它击中“咕噜声”时,它应该摧毁自己和咕噜声。但是,当它碰到边界时,它会破坏自身和边界的对撞机。我创建了一个自定义标签脚本,允许我将多个标签分配给一个游戏对象,而不是一个。
为什么它会破坏墙壁碰撞器?为什么它将墙壁和咕噜声都检测为咕噜声?我将如何修复它?
这是导致问题的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyProjectile : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
//FIX detects only grunt
private void OnTriggerEnter(Collider other)
{
//Get Tag Component
Tags hitObject = other.GetComponent<Tags>();
//Collisions
if (hitObject.FindTag("boundary"))
{
//collision with wall
Debug.Log("Hit a Wall");
Destroy(gameObject);
}
else if (hitObject.FindTag("grunt"))
{
//collision with grunt
Debug.Log("Hit a Grunt");
Destroy(gameObject);
Destroy(other); //<---- Deletes Boundary Collider (Should be destroying the game object of the grunt, instead destroys the colliders of barriers and the grunt)
}
}
}
这是自定义标签脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tags : MonoBehaviour
{
public string[] startTags;
private static string[] tags;
private void Start()
{
tags = startTags;
}
public bool FindTag(string search)
{
bool results = false;
for (int i = 0; i < tags.Length; i++)
{
if(search == tags[i])
{
results = true;
break;
}
}
return results;
}
}
最佳答案
看来你有两个问题。
1) 首先是你的抛射物正在摧毁 grunt 的对撞机,而不是 grunt。这是因为您将对撞机传递给 destroy 函数,而不是 grunt:
Destroy(other);
改为使用
Destroy(other.gameobject);
我也会把这个放在
Destroy(gameObject);
2) 您的标签系统不工作。我猜这是因为
private static string[] tags;
是静态的。我会删除 static 修饰符,看看它是否有效。您也可以直接使用 startTags
,无需 start()
赋值。
Unity 也已经有了一个可能更适合这种检测的标签系统: https://docs.unity3d.com/Manual/Tags.html
关于c# - Projectile 将墙壁和 "grunt"检测为 "grunt",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58881471/
标题说的差不多。无论出于何种原因projectile-invalidate-cache不会从弹丸的缓存中删除死文件,或者至少不会从它呈现给我的结果中删除。我正在使用 Spacemacs,Emacs 的
运行 spacemacs 0.200.9@25.1.1 每次启动 spacemacs 时,都会出现以下错误,但不知道如何解决。 Error (use-package): org-projectile
我在 emacs 上使用 helm-projectile。我注意到 emacs 启动非常慢,大约 4 秒。而且弹丸查找模糊匹配也很慢,当我完整输入文件名时大约需要 3 秒。 我正在开发一个非常大的项目
是否有可能设置特定的颜色主题或只是 Hook 特定项目以运行自定义 elisp? 所以这个想法是当我从特定项目(路径)打开文件时自动设置颜色主题或背景颜色?例如。我可以在不同的框架中处理多个项目,并立
我想为没有本地 git、hg、bzr 等目录的项目设置弹丸项目,所以我不能使用它们的存储库作为项目文件的源。仅创建 .projectile 就足够了吗?根目录中的文件并使用 C-u C-c p f刷新
我使用 Emacs 的工作流程涉及检查许多不同的项目。它们的添加和删除非常频繁。目前这非常烦人且耗时: projectile-add-known-project 并设置新项目的路径 helm-proj
我定义了几个项目,当我运行C-c p p时,它将列出所有项目。现在我不想要一个项目,并且我已经删除了该项目下的 .projectile 文件,但它仍然显示。如何删除它? 最佳答案 函数projecti
我有一个从玩家发射的射弹预制件,当它与“边界”碰撞时,它应该摧毁自己,当它击中“咕噜声”时,它应该摧毁自己和咕噜声。但是,当它碰到边界时,它会破坏自身和边界的对撞机。我创建了一个自定义标签脚本,允许我
当高分上升到 30 时,我试图编辑射弹的速度。但是,代码运行良好,游戏正常运行,但射弹移动的速度仍然相同。 let touchLocation = touch.location(in: self)
我想知道如何对射弹(特别是 SKSpriteNode)施加力或推力,使其持续移动直到击中某物。我尝试了一些方法,比如像这样设置速度: let node = SKSpriteNode(imageName
嘿伙计们,很抱歉打扰你们,但为了让它发挥作用,我现在浪费了几个小时来修修补补。 代码工作正常,但射弹在发射后不断改变方向,因此我尝试为每个子弹分配其自己的目录值,并将移动子弹的射击函数放入射弹类中。但
我正在编写一款游戏,该游戏目前正处于项目的早期阶段,旨在尝试了解有关编码的更多信息。在我的游戏中,对象随机生成(绿色方 block ),而玩家(红色方 block )会避开它们。我在尝试从 x 轴上的
我正在构建一个小型物理引擎,它以给定的角度和速度发射射弹,并在每个时间间隔跟踪和显示速度/位置 vector 。目前,我的位置值 vars.posNew 似乎正在更新,但我无法获取我的 vars.x
本人刚接触Emacs,所以最近遇到了“如何在emacs中快速查找并打开文件?”的问题。 (类似于 sublime/atom 中的 Go-to,Cmd-P)。作为一种解决方案,我使用的是 project
好吧,这一切都发生在一个美好而简单的 2D 世界中......:) 假设我有一个位于 Apos 的静态物体 A,一个位于 Bpos 且速度为 bVelocity 的线性移动物体 B,以及一个速度为 A
我是一名优秀的程序员,十分优秀!