您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

32 行
1.0 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float sphereRadius = 5f;
private GameObject sphereColliderChild; // 用于存储包含SphereCollider的子物体
void Start()
{
// 创建一个新的空子物体
sphereColliderChild = new GameObject("SphereColliderChild");
// 将新创建的子物体设置为当前GameObject的子物体
sphereColliderChild.transform.SetParent(transform);
// 将子物体的位置设置为父物体的位置
sphereColliderChild.transform.position = transform.position;
// 添加并设置SphereCollider
SphereCollider sphereCollider = sphereColliderChild.AddComponent<SphereCollider>();
sphereCollider.radius = sphereRadius;
sphereCollider.isTrigger = true;
}
void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, sphereRadius);
}
}