producción de juegos de utilería
revisar
Esta vez presento principalmente el último juego del grupo y participo principalmente en el desarrollo de algunos accesorios.
La información de accesorios y la implementación del código se presentan a continuación.
contenido
herramienta
En este juego, los accesorios se generan aleatoriamente, incluidas minas, misiles, al azar (con sprint y sigilo) y botellas de sangre. Su control está determinado por un guión.
//生成道具
if(PhotonNetwork.IsMasterClient && PropsGameManager.instance.isGameStart)
{
//计时
if(currentTime > 0)
{
currentTime -= Time.deltaTime;
}
else
{
//判断道具数是否到达上限
if (currentCountInScene < maxSpawnCountPermit)
{
for (int i = 0; i < spawnCountOneTime; i++)
{
Vector3 pos = new Vector3(Random.Range(-18f, 18f), 1, Random.Range(-18f, 18f));
PhotonNetwork.Instantiate(Const.PUN_PROPS_GAME_PREFABS_BASEPATH
+ propsPrefabNameWithRandom[Random.Range(0, propsPrefabNameWithRandom.Length)]
, pos
, Quaternion.identity);
currentCountInScene++;
}
}
currentTime = spawnInterval;
}
}
Use un atributo para determinar qué tipo de accesorio es
public enum PropsType
{
None,
MissileProp, //炮弹
LandmineProp, //地雷
CloakProp,
HealthBottleProp, //血瓶
SpeedUpProp,//疾步
FlashSkill
}
Para cada accesorio de cumpleaños aleatorio, hay una secuencia de comandos para controlar la animación y el tipo de accesorio.
public PropsManager.PropsType propType = PropsManager.PropsType.HealthBottleProp;
El otro es el control de suspensión.
//悬浮
private void Move()
{
startPos = transform.position;
transform.DOPath(new Vector3[] {
startPos, transform.position + new Vector3(0, 0.5f, 0), startPos }, 2)//Vector3.up//new Vector3(0,0.5f,0)
.SetLoops(-1, LoopType.Restart);
transform.DOBlendableLocalRotateBy(new Vector3(0, 360, 0), 4f, RotateMode.FastBeyond360);
.SetLoops(-1, LoopType.Restart);//循环设置为-1为一直
}
Cada accesorio debe ser recogido, y esta lógica se realiza en el controlador de accesorios del personaje.
public void OnTriggerEnter(Collider other)//TODO:同步背包
{
//IsPickingPropUp
if (!other.gameObject.tag.Equals("DroppedProps"))
{
return;
}
if(other.gameObject.GetComponent<DroppedProps>() != null)
{
if (other.gameObject.GetComponent<DroppedProps>().propType == PropsManager.PropsType.HealthBottleProp)//血瓶不参与背包计算,且血瓶一个单独脚本执行逻辑
{
return;
}
}
//是否销毁(是否捡的起来)由玩家拥有者的背包判决。
int index = 0;
//***:主要用以通知主机,因为只有主机控制着销毁悬浮道具,可换为PhotonNetwork.IsMasterClient
if (!photonView.IsMine)
{
if (PhotonNetwork.IsMasterClient)
{
PhotonNetwork.Destroy(other.gameObject);
PropsManager.DecreaseCurrentCount();//场上数量-1
}
else
{
other.gameObject.SetActive(false);
}
}
else//自己
{
index = FindVacantIndex();
DroppedProps dp = other.gameObject.GetComponent<DroppedProps>();
DroppedRandomProps drp = other.gameObject.GetComponent<DroppedRandomProps>();
if (dp != null)
{
itemBag[index] = dp.propType; //添加背包里捡的道具的类型
//UI
bagItemsPanel.GetChild(index).GetComponent<Image>().sprite
= GetSpriteByPropType(dp.propType);
}
else if(drp != null)
{
itemBag[index] = drp.propType; //添加背包里捡的道具的类型
//UI
bagItemsPanel.GetChild(index).GetComponent<Image>().sprite
= GetSpriteByPropType(drp.propType);
}
other.gameObject.SetActive(false);
}
AudioManager.instance.PropsGamePickUp();
}
Cada pastilla es impulsada por un efecto de sonido.
En segundo lugar, use accesorios
La primera es la mina terrestre. Después de recoger la mina, si se usa, se tarda 3 segundos en colocarla y no se puede interrumpir durante el período. Luego, después de colocar la mina, habrá algunos efectos de partículas para recordar que hay minas terrestres en la zona.
private void UseProp(PropsManager.PropsType type)//TODO:E技能计时UI
{
switch (type)
{
case PropsManager.PropsType.None:
AudioManager.instance.NoProps();
break;
case PropsManager.PropsType.LandmineProp:
//先判断当前执行的动画是不是站立idel
if (animator.GetCurrentAnimatorStateInfo(0).IsName("IdleNormal02_AR_Anim"))
{
Debug.Log("执行放置地雷的操作1");
DoAnimationWithEffect(2);
//创建地雷的方法
StartCoroutine(CreateLandMine(this.gameObject.transform.position));
}
else//不在空闲状态无法放置
{
tipText.text = "放置被打断";
Invoke("EmptyTipText", 1.5f);
}
break;
default:
break;
}
}
Usa rpc para generar minas
//生成地雷
private IEnumerator CreateLandMine(Vector3 v)
{
AudioManager.instance.SetLandmine(v);
yield return new WaitForSeconds(3); //等待3秒
v.y = 0.001f;
photonView.RPC("LandMineCreate", RpcTarget.AllViaServer, v);
}
[PunRPC]
public void LandMineCreate(Vector3 pos) //使用rpc进行生成地雷,同步其他所有的人,都会生成地雷。
{
GameObject landmine = Instantiate(landminePrefab, pos, Quaternion.identity);
}
Resumir
Esta vez, la introducción principal es la generación y colocación de minas, y la destrucción de minas y otros accesorios se presentarán más adelante.