Hello.
I’ve searched the forums, but did not find a answer to my problem or then it just eluded me.
I’ve just started Unity and doing all sorts of tutorials. Im doing this Flappy bird tutorial at the moment:
and at 50.04 where we should write script for TapController my Visual studio code - editor says everythings is fine, but my bird is not doing the same as it should according to the tutorial, in fact the bird is not doing anything except falling.
In Unity console I’m getting this error:
NullReferenceException: Object reference not set to an instance of an object
TapControlPlayer.Update () (at Assets/Scripts/TapControlPlayer.cs:28)
And here’s my script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class TapControlPlayer : MonoBehaviour
{
public float tapForce = 10;
public float tiltSmooth = 5;
public Vector3 startPos;
Rigidbody2D rigidBody;
Quaternion downRotation;
Quaternion forwardRotation;
void start(){
rigidBody = GetComponent<Rigidbody2D>();
downRotation = Quaternion.Euler(0,0,-100);
forwardRotation = Quaternion.Euler(0,0,40);
}
void Update() {
if (Input.GetMouseButtonDown(0)) {
transform.rotation = forwardRotation;
rigidBody.AddForce(Vector2.up * tapForce, ForceMode2D.Force);
}
transform.rotation = Quaternion.Lerp(transform.rotation, downRotation, tiltSmooth * Time.deltaTime);
}
void OnTriggerEnter2D(Collider2D col) {
if (col.gameObject.tag == "ScoreZone") {
//register a score event
//play a sound
}
if (col.gameObject.tag == "DeadZone") {
rigidBody.simulated = false;
//register dead event
//play a sound
}
}
}
Double-clicking the console error message points me to the line 29, but I have no idea what I should be doing differently. Especially as it is working for the gentleman in the tutorial.
For this tutorial I’m using Unity 5.6.7f build as I pretty sure the tutorial is made with 5.6
Thanks in advance for all the help!