unity3d - 错误 CS0177:“Debug”不包含“DrawLine”的定义
问题描述
我正在为 fps 突击步枪编写脚本。我收到此错误:“错误 CS0177:“调试”不包含“DrawLine”的定义。“我无法修复此错误,有人可以帮忙吗?
脚本如下所示:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class weaponController : MonoBehaviour
{
public float fireRate = 20f;
public GameObject cameraGameObject;
private void FixedUpdate() {
if(Input.GetKeyDown("fire1")){
fire();
}
}
private void fire(){
RaycastHit hit;
if(Physics.Raycast(cameraGameObject.transform.position,cameraGameObject.transform.forward,out hit)){
Debug.Drawline(transform.position,hit.pos);
}
}
}
解决方案
你需要写DrawLine
。不是Drawline
。C# 区分大小写。这意味着DrawLine
和Drawline
是不同的功能。将您的脚本更改为:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class weaponController : MonoBehaviour
{
public float fireRate = 20f;
public GameObject cameraGameObject;
private void FixedUpdate() {
if(Input.GetKeyDown("fire1")){
fire();
}
}
private void fire(){
RaycastHit hit;
if(Physics.Raycast(cameraGameObject.transform.position,cameraGameObject.transform.forward,out hit)){
Debug.DrawLine(transform.position,hit.point);
}
}
}
检查最后一行之一。我将“l”更改为“L”。
对于你的粒子效果:
public ParticleSystem ps;
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
flash.Play();
}
}
(确保粒子已将'play on awake' 设置为false。)将粒子系统放入inspector 中称为'ps' 的槽中。如果您希望粒子系统就在您的玩家旁边,请确保粒子系统是玩家的孩子。
这是另一个您可以根据需要使用的粒子系统。这个比上一个好,因为它实例化了粒子系统而不是仅仅播放它。
GameObject ps;
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
Instantiate(ps, transform.position);
}
}
将粒子系统拖入 ps 槽。这次是一个游戏对象,因为我们可以实例化游戏对象。在闪光灯的粒子系统设置中,激活唤醒时播放。然后向这个粒子系统添加一个脚本,设置为:
void Start()
{
Destroy(gameObject, 1f);
}
其中第二个变量是您想要破坏粒子系统之前的秒数。
推荐阅读
- c++ - Function pow doesn't show the right answer
- pandas - 在 DataFrame 'ValueError: Lengths must match to compare' 中选择两个日期之间的数据
- scala - 使用 akka-stream-alpakka 从 s3 下载 pdf 文件
- mysql - Sequel Pro gives 'Connection failed!' error using Docker Mysql container
- flutter - Flutter Widget that shows text line by line?
- angularjs - Angularjs: initiating first tab as active on page load
- git - 确定上次提交特定文件的版本 (SHA)
- c# - .NET Azure Functions - 依赖注入问题
- java - 创建 POJO 并从 Map 填充它
- nginx - Nginx 不关心新的虚拟主机