gpt4 book ai didi

c# - 球体对撞机碰撞射击玩家船?

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:21 29 4
gpt4 key购买 nike

好吧,我在看向我方面取得了一些进展,我能够让敌舰跟随玩家,激光枪也可以使用一些指导如何让激光杀死玩家飞船并提示丢失和“R”表示重新启动消息欢迎 Aanty 洞察如何去做。

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class EnemyManagement : MonoBehaviour
{
[SerializeField] GameObject deathFX;
[SerializeField] Transform parent;
// The target marker.
[SerializeField] Transform target;

// Angular speed in radians per sec.
[SerializeField] float speed;

// Start is called before the first frame update
void Start()
{
AddSphereCollider();
}

private void AddSphereCollider()
{
Collider sphereCollider = gameObject.AddComponent<SphereCollider>();
sphereCollider.isTrigger = false;
}

void Update()
{
Vector3 targetDir = target.position - transform.position;

// The step size is equal to speed times frame time.
float step = speed * Time.deltaTime;

Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0f);
Debug.DrawRay(transform.position, newDir, Color.red);

// Move our position a step closer to the target.
transform.rotation = Quaternion.LookRotation(newDir);
}
}

最佳答案

你需要给它一个碰撞检测的半径。

sphereCollider.radius = 10.0f;

关于c# - 球体对撞机碰撞射击玩家船?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54722342/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com