Hello,我是小恐龙。
今天我们来看一个寻找质数的APK:
在面板中的设置需要注意的有两点:
一是输入框需要输入数字类型的字符,否则的话不能转成整数。这个只需把InputField的Content Type设置成整数就行了。
二是滚动条要完美适应内容。这个在Text面板中添加Content Size Fitter组件,然后选择Preferred Size就好了,这样文本框既不会显示不全,也不会出现大片空白。
关于代码部分问题不大,跟Python几乎一样,直接贴上来:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Prime : MonoBehaviour
{
Text p;
Text title;
InputField start;
InputField end;
int a; //起始数字
int b; //结束数字
int n; //计数器
string s; //输入的起始字符
string e; //输入的结束字符
bool r; //测试是否是质数
// Start is called before the first frame update
void Start()
{
title = Game