前几天上课看见舍友在玩斗兽棋 然后我下来想着也用unity实现一个
之后给大家分享一下
首先给大家一个我在网上找到的图片
之后大家可以用unity自带的切割图片的功能 去切割
之前我写的教程地址(给大家参考)
然后我们的思路是使用射线(从摄像头发出)检测点击的物体 当然使用特定的接口通过UGUII也可以实现
同样给出几篇我之前写过的博客给大家参考
然后呢就开始开发阶段了 我们在选择两个相邻的动物之后 我们可以给每个动物写一个单独的脚本
之后获取其中的一个值 通过对比这个值 来判断吃与被吃的关系
预览游戏
我做的这个demo和我们常见的 斗兽棋不一样 我做的这个是默认都为黑色
之后两个玩家交互的翻牌 之后一方为红一方为蓝
所以由于这个特性 我们每次图片必须打乱 从而实现游戏的可玩性(保持随机性)
开发过程
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum PlayerType
{
red,
blue
};
/// <summary>
/// 每个动物身上挂在的脚本(通过这个脚本来判断吃与被吃的关系)
/// </summary>
public class Animal : MonoBehaviour
{
public int Hp;//hp越大 优先级越高(越厉害)
public PlayerType type;//判断是什么玩家
public SpriteRenderer Black;
private BoxCollider collider;
public BoxCollider blackcollider;
float timer = 0;
private void Start()
{
collider = GetComponent<BoxCollider>();
collider.enabled = false;
}
private void Update()
{
if (Black.enabled==false)
{
collider.enabled = true;
blackcollider.enabled = false;
}
}
public void Eated()
{
if (type == PlayerType. red)
{
Arrange.Instance.rednum--;
}
if (type == PlayerType.blue)
{
Arrange.Instance.bluenum--;
}
//被吃掉的方法
gameObject.SetActive(false);
}
/// <summary>
/// 移动到目标位置去
/// </summary>
public void MoveToTargetPosi(Vector3 Targetposi)
{
timer += Time.deltaTime;
if (timer > 1)
{
timer = 0;
}
transform.position