こちらのサイトで勉強しています。
https://openbook4.me/projects/161/sections/1023
サイトではjsで書かれているのでそれをc#で書き直して勉強しています。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Component; public class Ball : MonoBehaviour { public float Speed = 15.0f; void Start () { Rigidbody rigidbody = GetComponent<Rigidbody>(); } void Update () { if (Input.GetButtonUp("Jump") && rigidbody.velocity == new Vector3(0, 0, 0)){ rigidbody.AddForce((transform.forward + transform.right) * Speed, ForceMode.VelocityChange); } } }
var Speed : float = 15.0; function Update () { if (Input.GetButtonUp("Jump") && rigidbody.velocity == Vector3(0, 0, 0)){ rigidbody.AddForce((transform.forward + transform.right) * Speed, ForceMode.VelocityChange); } }
Assets/Ball.cs(4,1): error CS0138: A `using' directive can only be applied to namespaces but `UnityEngine.Component' denotes a type. Consider using a `using static' instead
たぶん初歩的なミスか、書き間違いだと思いますが分かりませんでした。
回答していただけると嬉しいです。
###追記
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Ball : MonoBehaviour { public float Speed = 15.0f; void Start () { Rigidbody rigidbody = GetComponent<Rigidbody>(); } void Update () { if (Input.GetButtonUp("Jump") && rigidbody.velocity == new Vector3(0, 0, 0)){ rigidbody.AddForce((transform.forward + transform.right) * Speed, ForceMode.VelocityChange); } } }
Assets/Ball.cs(9,20): warning CS0219: The variable `rigidbody' is assigned but its value is never used
Assets/Ball.cs(14,48): error CS1061: Type `UnityEngine.Component' does not contain a definition for `velocity' and no extension method `velocity' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?
Assets/Ball.cs(15,20): error CS1061: Type `UnityEngine.Component' does not contain a definition for `AddForce' and no extension method `AddForce' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/16 08:49
2018/02/16 08:54
2018/02/16 09:01
2018/02/16 09:06
2018/02/16 09:10
2018/02/16 09:31