c# - 如何修复“无法将转换类型 'float' 隐式转换为 'UnityEngine.Quaternion'”?
问题描述
我一直有这个问题,无法弄清楚如何解决它。我正在制作一个 2D 游戏,需要一个旋转和收缩的六边形。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hexagon : MonoBehaviour
{
public Rigidbody 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;
if (transform.localScale.x <= .05f)
{
Destroy(gameObject);
}
}
}
我是编程新手,需要帮助。
解决方案
这可以工作
using System.Collections;
使用 System.Collections.Generic;使用 UnityEngine;
公共类 ob : MonoBehaviour { 公共刚体 rb;
public float shrinkspeed = 4f;
// Start is called before the first frame update
void Start()
{
Quaternion randYRotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
transform.rotation = randYRotation;
transform.localScale = Vector3.one *10f;
}
// Update is called once per frame
void Update()
{
transform.localScale -= Vector3.one * shrinkspeed * Time.deltaTime;
if (transform.localScale.x <= .05f)
{
Destroy(gameObject);
}
}
}
推荐阅读
- sql - 在 Oracle 11g 上将行转换为列
- javascript - Vue CLI 3 预渲染水疗插件
- python - 如何在 argparse 中使用条件语句?
- bash - anaconda2 在 sudo rm -rf 之后仍然显示在主目录中
- amazon-dynamodb - 为什么我的 CloudFormation 模板在构建具有单个分区键的简单 DynamoDB 时总是失败?
- spring-boot - 带有 Thymeleaf 的 SpringBoot“未找到获取资源”
- sql - 如何优化查询以获取基于每个 ID 的值?
- javascript - 关闭由 window.open() 创建的 chrome 弹出窗口时如何防止内存泄漏
- python - 使用scrapy找到正确的分页选择器
- ios - 升级到 Xcode 9/10 后无法编译旧项目:GLKit / common.h 中出现“Expected unqualified-id”错误