美文网首页
Unity-3D RockMouse小游戏开发

Unity-3D RockMouse小游戏开发

作者: 一世长安乱 | 来源:发表于2018-04-10 16:32 被阅读0次
  • 载入图片和音频文件


    这里写图片描述
  • 为飞鼠添加原件
这里写图片描述
  • 添加刚体,相当于给飞鼠添加重力加速度
    这里写图片描述
    在此可以修改重力加速度的倍数
    这里写图片描述
    在此可以修改重力加速度的大小
    这里写图片描述
    这里写图片描述
  • 为飞鼠添加一个碰撞判定圈


    这里写图片描述
    这里写图片描述

    添加过后就会发现飞鼠周围有一个绿色的圆圈


    这里写图片描述
  • 为飞鼠增加一个脚本 点击鼠标左键使飞鼠向上位移
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseControl : MonoBehaviour {
    public float jetpackForce = 75.0f;//定义一个力 使RockMouse发生位移
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    //系统自带的函数,不能写错
    void FixedUpdate(){
        bool ForceActive = Input.GetButton("Fire1");//布尔变量来接收是否点击鼠标左键
        if (ForceActive) {
            GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, jetpackForce));
            //GetComponent<Rigidbody2D> 获得刚体 再给这个刚体加一个力 
        }
    }
}
  • 没有限制的飞鼠会飞出屏幕外面,新增两个矩形碰撞体使他不会飞出


    这里写图片描述
这里写图片描述

上方红框限制位置和大小

相关文章

网友评论

      本文标题:Unity-3D RockMouse小游戏开发

      本文链接:https://www.haomeiwen.com/subject/nesnhftx.html