Unity3d制作一个简单粗暴的五子棋
最终效果
效果是这样的gif动图展示

项目源码
先把源码贴这
https://download.youkuaiyun.com/download/qq_33789001/15743651
绘制棋盘
绘制构思
先定一个白色背景,然后盘由黑色的线绘制,
15*15的棋盘 就需要15条横着的线,和15条竖着的线构成。
预制两条横竖的线,那么这两条线的两边分别画7条线。
一个7次的for循环就搞定了。
还有五个点,这个就预制好改一下位置就完成。
绘制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QiPanCreateor : MonoBehaviour
{
public GameObject LineMH,LineMV;
public GameObject Pnt1, Pnt2, Pnt3, Pnt4;
float width = 40;
void Start()
{
CreatorQiPan();
}
void CreatorQiPan() {
Pnt1.transform.localPosition = new Vector3(-width * 4, -width * 4, 0);
Pnt2.transform.localPosition = new Vector3(width * 4, -width * 4, 0);
Pnt3.transform.localPosition = new Vector3(-width * 4, width * 4, 0);
Pnt4.transform.localPosition = new Vector3(width * 4, width * 4, 0);
for (int i = 0; i < 7; i++)
{
GameObject H1 = GameObject.Instantiate<GameObject>(LineMH);
GameObject H2 = GameObject.Instantiate<GameObject>(LineMH);
GameObject V1 = GameObject.Instantiate<GameObject>(LineMV);
GameObject V2 = GameObject.Instantiate<GameObject>(LineMV);
H1.transform.SetParent(this.transform);
H1.transform.localScale = Vector3.one;
H1.transform.localPosition = new Vector3(0, width * (i + 1), 0);
H2.transform.SetParent(this.transform);
H2.transform.localScale = Vector3.one;
H2.transform.localPosition = new Vector3(0, -width * (i + 1), 0);
V1.transform.SetParent(this.transform);
V1.transform.localScale = Vector3.one;
V1.transform.localPosition = new Vector3(width * (i + 1), 0, 0);
V2.transform.SetParent(this.transform);
V2.transform.localScale = Vector3.one

本文介绍如何使用Unity3D快速搭建五子棋游戏,包括棋盘绘制、棋子放置逻辑及胜负判定等核心功能。
最低0.47元/天 解锁文章
717

被折叠的 条评论
为什么被折叠?



