找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
游戏黄埔已经开课啦,大家速速报名赶快上车
查看: 2088|回复: 2

《荒野枪手》素材

[复制链接]

162

主题

33

回帖

891

积分

管理员

积分
891
发表于 2025-1-3 11:10:26 | 显示全部楼层 |阅读模式
素材

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

162

主题

33

回帖

891

积分

管理员

积分
891
 楼主| 发表于 2025-1-3 11:14:36 来自手机 | 显示全部楼层
设计草图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

162

主题

33

回帖

891

积分

管理员

积分
891
 楼主| 发表于 2025-1-7 12:11:33 | 显示全部楼层
子弹脚本
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;

  4. public class Bullet : MonoBehaviour
  5. {
  6.     public float maxRight;
  7.     public float speed = 10f;
  8.     // Start is called before the first frame update
  9.     void Start()
  10.     {
  11.         maxRight = GameObject.Find("right").transform.position.x;
  12.     }

  13.     // Update is called once per frame
  14.     void Update()
  15.     {
  16.         //子弹飞行
  17.         transform.Translate(Vector2.right  * Time.deltaTime * speed);
  18.         //自动销毁
  19.         if (this.transform.position.x> maxRight)
  20.         {
  21.             DestroyImmediate(this.gameObject);
  22.         }
  23.     }
  24. }
复制代码


Player01脚本
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;

  5. public class PlayerController : MonoBehaviour
  6. {
  7.     public float fireRage=0.5f;
  8.     public float nextFire=0f;
  9.     public float speed = 1f;
  10.     public GameObject bullet;
  11.     private Transform shootingPos;
  12.     public float maxTop;
  13.     public float minDown;

  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         shootingPos = GameObject.Find("ShootingPos").transform;
  18.     }

  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.         print(Time.time);
  23.         //玩家移动脚本
  24.         float v=Input.GetAxisRaw("Vertical");
  25.         if (v != 0)
  26.         {
  27.             transform.Translate(Vector2.up * v * Time.deltaTime * speed);//(new Vector2(0,1))
  28.         }
  29.         //发射子弹
  30.         if (Input.GetKeyDown(KeyCode.U)&& Time.time> nextFire)
  31.         {
  32.             Instantiate(bullet, shootingPos.position, Quaternion.identity);
  33.             nextFire = Time.time+fireRage;
  34.         }

  35.         //控制玩家不要出边界
  36.         //上边界
  37.         if (this.transform.position.y>maxTop)
  38.         {
  39.             this.transform.position = new Vector3(this.transform.position.x, maxTop,this.transform.position.z);
  40.         }
  41.         //下边界
  42.         if (this.transform.position.y < minDown)
  43.         {
  44.             this.transform.position = new Vector3(this.transform.position.x, minDown, this.transform.position.z);
  45.         }
  46.     }
  47. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|平顶山市图灵科技 ( 豫ICP备2024088136号-1| 豫公网安备41040202000275号 )

GMT+8, 2025-5-23 06:15 , Processed in 0.045576 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表