I’m very new to Unity, game development, coding, all of it really. I thought I’d try cloning a game from watching a YouTube video and following it step by step, which I thought will help me understand the basics of things. So this code below is an exact copy of what a YouTuber wrote, which worked fine for him but not me. Also note: The script title and the name after “class” are identical, so that’s not the problem. Please tell me why else this error may occur, if I have a typo in the code that I’m unaware of, etc. I’d appreciate help so much as I’ve been stuck on this for days now.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class TapController : 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, -90);
forwardRotation = Quaternion.Euler(0, 0, 35);
}
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 a dead event
//play a sound
}
}
}