球形对撞机碰撞射击玩家飞船?

时间:2019-02-16 10:59:48

标签: c# unity3d

好吧,我朝我的方向取得了一些进步,我能够使敌舰跟随玩家,并且激光枪也可以使用一些指导,以获取激光杀死玩家的舰船并提示丢失,并在重新启动消息中使用“ 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);
    }
}

1 个答案:

答案 0 :(得分:1)

您需要为其提供半径以进行碰撞检测。

sphereCollider.radius = 10.0f;