Okay I know how to do all the animation and using the animator, but i’m having problems with telling my game to use the animation I did ( i.e. telling my script to use the animations i did)
This is my script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
Public class Playermovement : MonoBehaviour {
public float speed = 5f;
public Text ScoreText;
public AudioClip coinsound;
private Vector3 target;
private int Score;
void Start ()
{
target = transform.position;
Score = 0;
SetScoreText ();
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
Score = Score + 1;
SetScoreText ();
AudioSource.PlayClipAtPoint (coinsound, transform.position);
}
}
void SetScoreText ()
{
ScoreText.text = "Score: " + Score.ToString ();
}
void Update () {
if (Input.GetMouseButtonDown (0)) {
target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards (transform.position, target, speed * Time.deltaTime);
}
void LateUpdate () {
var left = Camera.main.ViewportToWorldPoint (Vector3.zero).x;
var right = Camera.main.ViewportToWorldPoint (Vector3.one).x;
var top = Camera.main.ViewportToWorldPoint (Vector3.zero).y;
var bottom = Camera.main.ViewportToWorldPoint (Vector3.one).y;
float x = transform.position.x, y = transform.position.y;
if (transform.position.x <= left + GetComponent<Renderer> ().bounds.extents.x) {
x = left + GetComponent<Renderer> ().bounds.extents.x;
} else if (transform.position.x >= right - GetComponent<Renderer> ().bounds.extents.x) {
x = right - GetComponent<Renderer> ().bounds.extents.x;
}
if (transform.position.y <= top + GetComponent<Renderer> ().bounds.extents.y) {
y = top + GetComponent<Renderer> ().bounds.extents.y;
} else if (transform.position.y >= bottom - GetComponent<Renderer> ().bounds.extents.y) {
y = bottom - GetComponent<Renderer> ().bounds.extents.y;
}
transform.position = new Vector3 (x, y, transform.position.z);
}
}