鱼C论坛

 找回密码
 立即注册
查看: 60|回复: 3

unity c#脚本中无法使用随机数

[复制链接]
发表于 2024-7-23 13:44:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这是在unity中打开的脚本,但是他提示
            if (Randow.Range(0f, 1f) > 0.5f)
这一句的
error CS0103: The name 'Randow' does not exist in the current context
这是为什么??
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyCreat : MonoBehaviour
{
    public GameObject enemyToCreat;

    public float timeToCreat;
    private float creatNumb;

    public Transform minCreat, maxCreat;
    // Start is called before the first frame update
    void Start()
    {
        creatNumb = timeToCreat;
    }

    // Update is called once per frame
    void Update()
    {
        creatNumb -= Time.deltaTime;
        if (creatNumb <= 0)
        {
            creatNumb = timeToCreat;
            //Instantiate(enemyToCreat, transform.position, transform.rotation);
            Instantiate(enemyToCreat, SelectCreatPoint(), transform.rotation);
        }
    }
    public Vector3 SelectCreatPoint()
    {
        Vector3 creatPoint = Vector3.zero;
        bool creatVerticalEdge = Randow.Range(0f, 1f) > 0.5f;

        if (creatVerticalEdge)
        {
            creatPoint.y = Randow.Range(minCreat.position.y, maxCreat.position.y);
            if (Randow.Range(0f, 1f) > 0.5f)
            {
                creatPoint.x = maxCreat.position.x;

            }
            else
            {
                creatPoint.x = minCreat.position.x;

            }
        }
        else
        {
            creatPoint.x = UnityEngine.Randow.Range(minCreat.position.x, maxCreat.position.x);
            if (Randow.Range(0f, 1f) > 0.5f)
            {
                creatPoint.y = maxCreat.position.y;

            }
            else
            {
                creatPoint.y = minCreat.position.y;

            }
        }
        return creatPoint;
    }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2024-7-23 13:54:15 | 显示全部楼层
好了,此贴完结,纯粹是写错了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-7-23 13:46:51 | 显示全部楼层
@FishC
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-7-23 21:53:49 | 显示全部楼层
跟我之前一样
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-8 09:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表