«Подарунок» від Unity
Привіт. Вирішив зайнятися розробкою власної гри і як «екземпляр» взяв відео за цією адресою (це 3 урок з 17)
www.youtube.com/...DjO8dL0Y6X0ZFGaMt&index=4
Я прописав код згідно інструкції... Все працювало нормально, а потім Unity зробило мені «Подарунок»: помилки, які я не можу прибрати, хоча код прописаний правильно...
КОД
using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Com.Kawaiisun.SimpleHostile { public class Move : MonoBehaviour { public float speed; public float sprintModifier; public float jumpForse; public Camera normalCam; public Transform groundDetector; public LayerMask ground; private Rigidbody rig; private float baseFOV; private float sprintFOVModifier = 1.5f; void Start() { baseFOV = normalCam.fieldOfView; Camera.main.enabled = false; rig = GetComponent(); } void FixedUpdate() { float t_hmove = Input.GetAxisRaw("Horizontal"); float t_vmove = Input.GetAxisRaw("Vertical"); bool sprint = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); bool jump = Input.GetKeyDown(KeyCode.Space); bool isgrounded = Physics.Raycast(groundDetector.position, Vector3.down, 0.1f, ground); bool isjumping = jump && isgrounded; bool issprinting = sprint && t_vmove > 0 && !isjumping && isgrounded; if (isjumping) { rig.AddForce(Vector3.up * jumpForse); } Vector3 t_direction = new Vector3(t_hmove, 0, t_vmove); t_direction.Normalize(); float t_adjustedspeed = speed; if (issprinting) { t_adjustedspeed *= speed; } Vector3 t_targetvelocity = transform.TransformDirection(t_direction) * t_adjustedspeed * Time.deltaTime; t_targetvelocity.y = rig.velocity.y; rig.velocity = t_targetvelocity; if (issprinting) { normalCam.fieldOfView = Mathf.Lerp(normalCam.fieldOfView, baseFOV * sprintFOVModifier, Time.deltaTime * 8f); } else { normalCam.fieldOfView = Mathf.Lerp(normalCam.fieldOfView, baseFOV, Time.deltaTime * 8f); } } } } Помилки NullReferenceException: Object reference not set to an instance of an object Com.Kawaiisun.SimpleHostile.Move.Start () (at Assets/Scripts/Move.cs:24) NullReferenceException: Object reference not set to an instance of an object Com.Kawaiisun.SimpleHostile.Move.FixedUpdate () (at Assets/Scripts/Move.cs:55)
Причому перша вискакує 1 раз, а друга — нескінченно...
Тому прошу тих, хто знається на Unity підкажіть, будь ласка, що треба зробити, щоб не видавало помилку... Якщо що версія Unity 2019.3
Також хочу спитати вашої поради з приводу мови програмування. Я знаю декілька мов програмування (Python, C++, JS, Java) але лише на базовому рівні (окрім Python)(змінні, типи даних, цикли, масиви, функції). А тому підкажіть, будь ласка, яку мову програмівання краще вивчати для того, аби створити гру. Дякую за увагу.
21 коментар
Додати коментар Підписатись на коментаріВідписатись від коментарів