unity3d~坦克AI(小练习)

本文通过Unity3D演示了坦克AI的实现,详细讲解了射线的应用,包括射线的描述、变量、构造函数及使用。同时介绍了Player、TankAI、AudioManage、EnemyAudioManage和CreateEnemyTank等关键脚本的作用,为游戏开发中的AI和交互提供参考。
摘要由CSDN通过智能技术生成

✨AI案例,如果觉得对你有用,请点赞收藏关注一波,谢谢支持😘

射线应用

struct in UnityEngine

1、描述

射线表示形式。
射线是从 origin 开始并按照某个 direction 行进的无限长的线。

2、变量

direction 射线的方向。
origin 射线的原点。

2.1、构造函数

Ray 沿着 direction 创建从 origin 开始的射线。

2.2、使用

声名 RaycastHit 、Ray;//
RaycastHit hit;
Ray ray;

Ray((起点)(方向))//
ray = new Ray(Vector3.up,Vector3.forward);

如果有监测到就返回true否者返回false;//
if (Physics.Raycast(ray, out hit)){

打印碰到的信息//
 Debug.DrawRay(ray.origin, ray.direction * 20, Color.red);
 Debug.DrawLine(ray.origin,ray.direction*20,Color.yellow);
Debug.Log(hit.collider.gameObject);
Debug.Log(hit.collider.tag);
Debug.Log(hit.point);
Debug.Log(hit.collider.transform.position);
Debug.Log(hit.collider.name);
}

3、案例脚本总结

Player

  • Player代码
//全局变量
private GameObject Tank;

private float rotationSpeed=2;
private float moveSpeed=50;

private float ver;
private float hor;

public GameObject sendPostion;
public GameObject bullet;

private GameObject bulletObj;
public float senSpeed=10;

public AudioClip clips;

void Update()
{
hor = Input.GetAxis("Horizontal");
ver = Input.GetAxis("Vertical");

transform.position += transform.forward * ver * moveSpeed * Time.deltaTime;
transform.eulerAngles += Vector
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SYFStrive

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值