Unity 欢乐球球
//—1 自己控制球的弹跳力代码如下 —2) 在Project视图中给球添加Physical Materical 设置弹力以后 拉给球的Collider的Materical 属性)
SphereCollider sphereCollider;
public float bounceSpeed;
public float gravity;
public float maxSpeed = 1;
float radius = 0;
float speed;
void Start()
{
sphereCollider = GetComponent();
radius = sphereCollider.radius;
}
//球掉落移动计算
void Drop()
{
//每帧减去模拟重力带来的速度影响
speed -= gravity * Time.deltaTime;
//限制球能达到的最大速度 speed = Mathf.Clamp(speed, -maxSpeed, maxSpeed); transform.position += new Vector3(0, speed, 0); } void Bounce() { //当球反弹回升的时候跳过检测 if (speed >= 0) { return; } //确定一个位置合适的立方体,比球略小,位置偏下 Vector3 p = transform.position + new Vector3(0, -radius, 0); Vector3 size = new Vector3(radius * 0.5f, radius * 0.5f, radius * 0.5f); if (Physics.OverlapBox(p, size, Quaternion.identity, LayerMask.GetMask("Ground")).Length > 0) { speed = bounceSpeed; } } void Update() { Bounce(); Drop(); }
}
//物体的旋转
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InputLogic : MonoBehaviour {
//记录上一帧鼠标的位置
Vector3 lastMousePos=Vector3.zero;
void TouchRotate()
{
//鼠标左键按下时转动
if (Input.GetMouseButton(0))
{
//计算这一帧鼠标位置与上一帧的差值,然后以Y轴转动
float moveX = (Input.mousePosition - lastMousePos).x;
transform.Rotate(0, -moveX, 0);
}
}
void Update()
{
TouchRotate();
lastMousePos = Input.mousePosition;
}
}
- 堆:欢乐和痛苦
- 在Unity開發App應該用PSD, PNG或TGA呢?
- 将Unity的脚本封装为dll文件(使用monodevelop编译器)
- [UnityShader基础]基本概念
- unity让物体鼠标平滑移动物体
- 怎么查看Unity是否破解成功
- unity manifest清单合并
- VC中的堆,欢乐和痛苦
- unity 2D行走动画
- Unity控制台日志开启重定向
- Unity编辑器界面模糊
- screen space directional occlusion(SSDO) in Unity5
- 【Unity】《Unity_API解析》 第四章 HideFlags类
- Unity BUG解决——从数据库中加载数据的时候无法同步显示到UI上
- EntLib 4.0 和 Unity 的开发团队
- Plugins in Unity
- Ubuntu14.04 在 vmware中进入unity模式方法
- Unity3D安装破解教程(以Unity5.3.4为例
- Unity GUI(uGUI)使用心得与性能总结
- unity-动画中加入触发事件