资源简介
此脚本用unity3D实现了简单2D计算器,实现计算器的加减乘除等功能,博客地址https://blog.csdn.net/qq874455953
代码片段和文件信息
using UnityEngine;
using System.Text.Regularexpressions;
using System.Collections.Generic;
using System;
using System.Linq;
public class NewBehaviourscript : MonoBehaviour
{
public static bool IsNumeric(string value)
{
return Regex.IsMatch(value @“^[+-]?\d*[.]?\d*$“);
}
//用来显示结果
public string result = ““;
//第一个操作数
public static string str1 = ““;
//第二个操作数
public static bool haveDot = false;
public static bool isCaclutate = false;
void OnGUI()
{
//对数字进行处理
if (GUI.Button(new Rect(100 100 100 60) “CE“))
{
result = ““;
str1 = ““;
haveDot = false;
}
if (GUI.Button(new Rect(210 100 100 60) “ד) && str1.Substring(str1.Length - 1 1) != “-“ && str1.Substring(str1.Length - 1 1) != “+“ && str1.Substring(str1.Length - 1 1) != “.“)
{
if (IsNumeric(str1.Substring(str1.Length - 1 1)))
{
Debug.Log(str1.Substring(str1.Length - 1 1));
str1 += “*“;
haveDot = false;
isCaclutate = false;
}
result = str1;
}
if (GUI.Button(new Rect(320 100 100 60) “÷“) && str1.Substring(str1.Length - 1 1) != “-“ && str1.Substring(str1.Length - 1 1) != “+“ && str1.Substring(str1.Length - 1 1) != “.“)
{
if (IsNumeric(str1.Substring(str1.Length - 1 1)))
{
str1 += “/“;
haveDot = false;
isCaclutate = false;
}
result = str1;
}
if (GUI.Button(new Rect(430 100 100 60) “←“))
{
if (isCaclutate == true)
{
str1 = ““;
isCaclutate = false;
} else if (result.Length != 0)
{
str1 = str1.Substring(0 str1.Length - 1);
}
result = str1;
}
if (GUI.Button(new Rect(100 170 100 60) “1“))
{
if (isCaclutate == true)
{
str1 = ““;
isCaclutate = false;
haveDot = false;
}
str1 += “1“;
result = str1;
}
if (GUI.Button(new Rect(210 170 100 60) “2“))
{
if (isCaclutate == true)
{
str1 = ““;
isCaclutate = false;
haveDot = false;
}
str1 += “2“;
result = str1;
}
if (GUI.Button(new Rect(320 170 100 60) “3“))
{
if (isCaclutate == true)
{
str1 = ““;
isCaclutate = false;
haveDot = false;
}
str1 += “3“;
result = str1;
}
if (GUI.Button(new
相关资源
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
- C#指纹识别系统程序 报告
- c# 高校档案信息管理系统
- c#向word文件插入图片
- C#左侧导航菜单(动态生成)
评论
共有 条评论