hey, I’m quite new to unity and coding so please pardon my ignorance, I’m getting this error on both line 20 and 49, I’ve marked “here” in a comment to show the lines,and I’ve spent a few hours trying to figure out whats wrong but I can’t. I know its probably something very trivial, any help is appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Character1_Controller : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
public int score = 0;
private Display display;
Animator anim;
void Start () {
anim = GetComponent<Animator>();
display = GetComponent<Display>();
display.UpdateScoreText(score);//here
}
void FixedUpdate () {
float move = Input.GetAxis("Horizontal");
anim.SetFloat("speed", Mathf.Abs(move));
GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Flip () {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
void OnTriggerEnter2D(Collider2D hit){
if(hit.CompareTag("apple")){
score++;
display.UpdateScoreText(score);//here
Destroy(hit.gameObject);
}
}
}