C#见缝插针

C#见缝插针


public Button yes;
    public Button no;
    public float angle = 70;
    public GameObject ti;
    public GameObject pi;

    void Start()
    {
        ti = GameObject.Find("Circle");
        yes = GameObject.Find("jiasu").GetComponent<Button>();
        yes.onClick.AddListener(on);
        no = GameObject.Find("jiansu").GetComponent<Button>();
        no.onClick.AddListener(yi);
        pi = GameObject.Find("Circle");


    }
    void Update ()
    {
        
        //当前脚本所在物体自转
        //第一个参数:旋转的轴
        //第二个参数:旋转的角度
        ti.transform.Rotate(-transform.forward,angle*Time.deltaTime);
    }
   public void on()
    {
        pi.GetComponent<RotateSelf>().angle *= 2;

    }
    public void yi()
    {
        pi.GetComponent<RotateSelf>().angle /= 2;

    }

向空气撒个娇(ง'-')ง 2019/3/13 9:08:21

public GameObject StartPoint;
    public Vector3 TargetPoint;
    public GameObject Circle;
    public bool ismove = false;
    bool isReach = true;
   
	void Start ()
    {
        
        StartPoint = GameObject.Find("Stop");
        Circle = GameObject.Find("Circle");
        TargetPoint = Circle.transform.position;
        TargetPoint.y -= 5f;
	}
	
	// Update is called once per frame
	void Update ()
    {
       //物体移动的目标点
       //第一个参数:物体的坐标点
       //第二个参数:物体运动的目标点
       //第三个参数:物体一次运动的距离
        if (ismove)
        {
            //物体移动到目标点TargetPoint
            transform.position = Vector3.MoveTowards(transform.position, TargetPoint,10f);
            if (Vector3.Distance(transform.position, TargetPoint) < 0.05f)
            {
                transform.position = TargetPoint;
                transform.parent = Circle.transform;
                ismove = false;
            }
        }
        else
        {
            if (isReach)
            {
                //物体移动到目标点StartPoint
               transform.position = Vector3.MoveTowards(transform.position, StartPoint.transform.position, 5f);
                if (Vector3.Distance(transform.position, StartPoint.transform.position) < 0.05f)
                {
                    transform.position = StartPoint.transform.position;
                    isReach = false;
                }

            }
        }
	}
    public void ChangeFlag()
    {
        ismove = true;
        isReach = false;
    }

向空气撒个娇(ง'-')ง 2019/3/13 9:09:05

 public GameObject Pin;
   public GameObject SpawnPoint;
    public GameObject pinGame;
    public int Score = 0;
    public Text Scoretext;
    public bool isgameover = false; 
    public Camera cam;
    void Start ()
    {
        cam= Camera.main;
        SpawnPoint = GameObject.Find("Go");
        Function();
        
	}
	
	// Update is called once per frame
	void Update ()
    {
        if (isgameover)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            Score++;
            Scoretext.text = Score.ToString();
            pinGame.GetComponent<Pin>().ChangeFlag();
            Function();
        }
	}
    public void Function()
    {
        //克隆函数
        //第一个参数:要克隆的物体
        //第二个参数:克隆的位置
        //第三个参数:克隆的角度
        pinGame = (GameObject)Instantiate(Resources.Load("Pin"), SpawnPoint.transform.position, Quaternion.Euler(new Vector3(0, 0, 90)));
    }
    public void IsGameOver()
    {
        isgameover = true;
        StartCoroutine(Load()); 
    }
    IEnumerator Load()
    {
        while (true)
        {
            //相机渐变为绿色
            cam.backgroundColor = Color.Lerp(cam.backgroundColor, Color.black  , 0.01f);
            //相机渐变为较近位置
            cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, 40,0.01f);
            if (Mathf.Abs(cam.orthographicSize - 40) < 0.001f)
            {
                break;
            }
            //等待一帧
            yield return 0;
        }
        //等待一秒
        yield return new WaitForSeconds(0.001f);
        SceneManager.LoadScene("NewGame");
    }

向空气撒个娇(ง'-')ง 2019/3/13 9:09:26

  private void OnTriggerEnter2D(Collider2D collision)
    {
      
        //判断碰到的是不是针头
        if (collision.gameObject.tag == "Head")
        {
            //圆圈不在转动
            GameObject.Find("Circle").GetComponent<RotateSelf>().enabled = false;
           //跳转场景
            GameObject.Find("oo").GetComponent<GameManger>().IsGameOver();
        }
    } 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值