//模拟计算器
//乘法要求两个数必须是质数,否则返回-1
//除法要求两个数的最大公约数为1,否则返回-1
调用代码
void Start () {
print(Test.Instance.Cal(3, 4, Test.Instance.Add));
}
主代码
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
//模拟计算器
//乘法要求两个数必须是质数,否则返回-1
//除法要求两个数的最大公约数为1,否则返回-1
private static Test instance;
public static Test Instance {
get {
if (instance==null )
{
GameObject obj=new GameObject("B");
instance = obj.AddComponent<Test>();
DontDestroyOnLoad(obj);
}
return instance;
}
}
void Start()
{
//print(Cal(3, 5, Add));
//Cal(3, 2, Add);
}
public float Cal(int a,int b,System.Func<int,int,float> oper )//最后一个参数时返回值类型
{