火箭耗子 5.1 AddForce 加前进的速度 设置离子的层 Physics2D.OverlapCircleAll
来源:互联网 发布:手机制作奖状软件 编辑:程序博客网 时间:2024/05/02 01:06
当按下鼠标的时候给物理加力 5.0后要获取组件然后加AddForce
public float jetpackForce = 75.0f;
void FixedUpdate ()
{
bool jetpackActive = Input.GetButton("Fire1");
if (jetpackActive)
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jetpackForce));
}
Vector2 newVelocity = GetComponent<Rigidbody2D>().velocity;速度矢量传递
newVelocity.x = forwardMovementSpeed;
GetComponent<Rigidbody2D>().velocity = newVelocity;
}
GetComponent<ParticleSystemRenderer> ().sortingLayerName="Player"; 设置粒子系统的层级
GetComponent<ParticleSystemRenderer> ().sortingOrder = -1;
Collider2D[] enemies = Physics2D.OverlapCircleAll(transform.position, bombRadius, 1 << LayerMask.NameToLayer("Enemies"));
这个方法定义了一个2D碰撞数组,以指定的顶点为圆心(transform.position),设置圆的半径(bombRadius),在指定的层(1 << LayerMask.NameToLayer("Enemies"))作用。
在这个层里指定圆的范围内添加所有包涵collider的个体。返回数组中的个体按照Z递增排列。
这个方法定义了一个2D碰撞数组,以指定的顶点为圆心(transform.position),设置圆的半径(bombRadius),在指定的层(1 << LayerMask.NameToLayer("Enemies"))作用。
在这个层里指定圆的范围内添加所有包涵collider的个体。返回数组中的个体按照Z递增排列。
public class MouseController : MonoBehaviour {
public float jetpackForce = 75.0f;
public float forwardMovementSpeed = 3.0f;
public float forwardAddSpeed = 0.03f;
public Transform groundCheckTransform;
private bool grounded;
public LayerMask groundCheckLayerMask;
Animator animator;
public ParticleSystem jetpack;
private bool dead = false;
private uint coins = 0;
public AudioClip coinCollectSound;
public AudioSource jetpackAudio;
public AudioSource footstepsAudio;
//public ParallaxScroll parallax;
public Text coinsLabel;
void Start (){
animator = GetComponent<Animator>();
}
void FixedUpdate ()
{
if(forwardMovementSpeed <= 10)
{
forwardMovementSpeed += forwardAddSpeed;
}
bool jetpackActive = Input.GetButton("Fire1");
jetpackActive = jetpackActive && !dead;
//parallax.offset = transform.position.x;
if (jetpackActive)
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jetpackForce));
}
if(!dead){
Vector2 newVelocity = GetComponent<Rigidbody2D>().velocity;
newVelocity.x = forwardMovementSpeed;
GetComponent<Rigidbody2D>().velocity = newVelocity;
}
UpdateGroundedStatus();
AdjustJetpack (jetpackActive);
AdjustFootstepsAndJetpackSound(jetpackActive);
}
void UpdateGroundedStatus()
{
//1
grounded = Physics2D.OverlapCircle(groundCheckTransform.position, 0.4f, groundCheckLayerMask); //返回布尔,检测0.4为半径的园,到地面的距离
//2
animator.SetBool("grounded", grounded);
}
void AdjustJetpack (bool jetpackActive)
{
if(!dead){
jetpack.enableEmission = !grounded;
jetpack.emissionRate = jetpackActive ? 400.0f : 50.0f;
}
}
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.CompareTag("Coins"))
CollectCoin(collider);
else
HitByLaser(collider);
}
void HitByLaser(Collider2D laserCollider)
{
if (!dead)
laserCollider.gameObject.GetComponent<AudioSource>().Play();
dead = true;
jetpack.enableEmission = false;
animator.SetBool("dead", true);
}
void CollectCoin(Collider2D coinCollider)
{
coins++;
Destroy(coinCollider.gameObject);
AudioSource.PlayClipAtPoint(coinCollectSound, transform.position);
coinsLabel.text = coins.ToString();
}
void AdjustFootstepsAndJetpackSound(bool jetpackActive)
{
footstepsAudio.enabled = !dead && grounded;
jetpackAudio.enabled = !dead && !grounded;
jetpackAudio.volume = jetpackActive ? 1.0f : 0.5f;
}
}
public float jetpackForce = 75.0f;
public float forwardMovementSpeed = 3.0f;
public float forwardAddSpeed = 0.03f;
public Transform groundCheckTransform;
private bool grounded;
public LayerMask groundCheckLayerMask;
Animator animator;
public ParticleSystem jetpack;
private bool dead = false;
private uint coins = 0;
public AudioClip coinCollectSound;
public AudioSource jetpackAudio;
public AudioSource footstepsAudio;
//public ParallaxScroll parallax;
public Text coinsLabel;
void Start (){
animator = GetComponent<Animator>();
}
void FixedUpdate ()
{
if(forwardMovementSpeed <= 10)
{
forwardMovementSpeed += forwardAddSpeed;
}
bool jetpackActive = Input.GetButton("Fire1");
jetpackActive = jetpackActive && !dead;
//parallax.offset = transform.position.x;
if (jetpackActive)
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jetpackForce));
}
if(!dead){
Vector2 newVelocity = GetComponent<Rigidbody2D>().velocity;
newVelocity.x = forwardMovementSpeed;
GetComponent<Rigidbody2D>().velocity = newVelocity;
}
UpdateGroundedStatus();
AdjustJetpack (jetpackActive);
AdjustFootstepsAndJetpackSound(jetpackActive);
}
void UpdateGroundedStatus()
{
//1
grounded = Physics2D.OverlapCircle(groundCheckTransform.position, 0.4f, groundCheckLayerMask); //返回布尔,检测0.4为半径的园,到地面的距离
//2
animator.SetBool("grounded", grounded);
}
void AdjustJetpack (bool jetpackActive)
{
if(!dead){
jetpack.enableEmission = !grounded;
jetpack.emissionRate = jetpackActive ? 400.0f : 50.0f;
}
}
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.CompareTag("Coins"))
CollectCoin(collider);
else
HitByLaser(collider);
}
void HitByLaser(Collider2D laserCollider)
{
if (!dead)
laserCollider.gameObject.GetComponent<AudioSource>().Play();
dead = true;
jetpack.enableEmission = false;
animator.SetBool("dead", true);
}
void CollectCoin(Collider2D coinCollider)
{
coins++;
Destroy(coinCollider.gameObject);
AudioSource.PlayClipAtPoint(coinCollectSound, transform.position);
coinsLabel.text = coins.ToString();
}
void AdjustFootstepsAndJetpackSound(bool jetpackActive)
{
footstepsAudio.enabled = !dead && grounded;
jetpackAudio.enabled = !dead && !grounded;
jetpackAudio.volume = jetpackActive ? 1.0f : 0.5f;
}
}
-------------------------------------------
using UnityEngine;
using System.Collections;
// 背景移动 设置主相机背景为景深 挂到副相机上
public class ParallaxScroll : MonoBehaviour {
public Renderer background;
public Renderer foreground;
public float backgroundSpeed = 0.02f;
public float foregroundSpeed = 0.06f;
public float offset = 0;
// Update is called once per frame
void Update () {
float backgroundOffset = Time.timeSinceLevelLoad * backgroundSpeed;
float foregroundOffset = Time.timeSinceLevelLoad* foregroundSpeed;
background.material.mainTextureOffset = new Vector2(backgroundOffset, 0);
foreground.material.mainTextureOffset = new Vector2(foregroundOffset, 0);
}
}
using System.Collections;
// 背景移动 设置主相机背景为景深 挂到副相机上
public class ParallaxScroll : MonoBehaviour {
public Renderer background;
public Renderer foreground;
public float backgroundSpeed = 0.02f;
public float foregroundSpeed = 0.06f;
public float offset = 0;
// Update is called once per frame
void Update () {
float backgroundOffset = Time.timeSinceLevelLoad * backgroundSpeed;
float foregroundOffset = Time.timeSinceLevelLoad* foregroundSpeed;
background.material.mainTextureOffset = new Vector2(backgroundOffset, 0);
foreground.material.mainTextureOffset = new Vector2(foregroundOffset, 0);
}
}
0 0
- 火箭耗子 5.1 AddForce 加前进的速度 设置离子的层 Physics2D.OverlapCircleAll
- 离子炮的实现
- Physics2D.Linecast的使用注意事项
- 耗子给的意见
- 原子和离子的区别
- 开源加快了软件产业前进的速度
- 开源加快了软件产业前进的速度
- Physics2D 检测圆形区域内的所有碰撞器
- 程序员是燃废的火箭
- 火箭的常规赛
- 当回拿耗子的狗
- 左耳朵耗子给出的学习指南
- 左耳朵耗子给出的学习指南
- Unity3D中Rigidbody.velocity和Addforce的区别
- 让你的微小离子随机分布更均匀--布朗运动
- 离子感烟探测器的工作原理介绍
- 问,江阴哪里的离子烫比较好呢?
- coco2d-x中引用离子效果,游戏计数的方法
- winform——文本文档
- 黑马day16 子jquery&子元素过滤选择器
- winfrom——文本内容存入流
- android 之.9.png ”点九” 图片制作方法
- 曝光补偿
- 火箭耗子 5.1 AddForce 加前进的速度 设置离子的层 Physics2D.OverlapCircleAll
- C++知识点总结
- mosquitto配置与使用
- UIAlertView和UIActionSheet
- Builder模式
- quick3x_保证下标顺序排列,删除table中的元素
- IOS多线程开发其实很简单
- 诸葛告诉你怎样解读数据分析结果?
- 2-11. 两个有序链表序列的合并(15):链表数据结构基础练习