Unity3d制作一个简单粗暴的五子棋项目工程源码

本文介绍如何使用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

十幺卜入

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

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

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

打赏作者

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

抵扣说明:

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

余额充值