繁体   English   中英

如何在统一 2D 中随机加速我的游戏对象

[英]How to randomly speed up my game object in unity 2D

嘿,所以我不知道如何对我的游戏对象实施随机加速,如果有人能帮助我,我会被卡住一段时间。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hexagon : MonoBehaviour
{

public Rigidbody2D rb;

public float shrinkSpeed = 3f;

// Start is called before the first frame update
void Start()
{
    rb.rotation = Random.Range(0f, 360f);
    transform.localScale = Vector3.one * 10f;
}

// Update is called once per frame
void Update()
{
    transform.localScale -= Vector3.one * shrinkSpeed * Time.deltaTime * 2;

    if(transform.localScale.x <= .05f)
    {
        Destroy(gameObject);
    }
}

}
private void RandomSpeedUp()
{
    float minSpeedUp = 1.3f; //30% speed boost
    float maxSpeedUp = 1.75f; //75% speed boos

    rb.velocity*= Random.Range(minSpeedUp, maxSpeedUp);
}

这应该是一个很好的起点

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM