Hello
I am really new to unity and creating my first game. Can anyone please tell me how to move the character in one direction or to move him back. And also the functionality of **isKinematic**?
And also I am having this problem in my script there are showing a lot of errors which just happened suddenly but I can play the scene in unity. It's saying " Ambiguity between "controller.animator" and "controller.animator". Having 19 of this errors.
P.S : The code was ok just few minutes ago then suddenly this happened.
Here is the code
public class controller : MonoBehaviour
{
private bool isGrounded;
private float radius = 0.7f;
private float force = 300f;
//public float movementSpeed = 5.0f;
public Transform coinsParent;
public Transform groundPoint;
public LayerMask ground;
public AudioSource audiosSource;
public AudioClip Jumpp;
public AudioClip Coin;
public AudioClip Win;
public Animator animator;
public int coins;
//public Game gameComponent;//game reference;
public TextMesh score;
bool jumped;
float jumpTime = 0;
float jumpDelay = 0.5f;
void start()
{
animator = GetComponent();
}
//update is called once per frame
void Update()
{
isGrounded = Physics2D.OverlapCircle(groundPoint.position, radius, ground);
if (isGrounded)
{
if (Input.GetMouseButtonDown(0))
{
gameObject.GetComponent().AddForce(Vector2.up * 300);
audioSource.clip = Jump;
audioSource.Play();
jumpTime = jumpDelay;
jumped = true;
animator.SetTrigger("jumped");
}
/* {
if(Input.GetKey(KeyCode.D)) {
transform.position += Vector3.forward * Time.deltaTime * movementSpeed;
}
else if(Input.GetKey(KeyCode.A)) {
transform.position -= transform.forward * Time.deltaTime * movementSpeed;
}*/
}
jumpTime -= Time.deltaTime;
if (jumpTime <= 0 && isGrounded && jumped)
{
animator.SetTrigger("landed");
jumped = false;
}
void OnTriggerEnder2D (Collider2D collider2d)
{
if (collider2D.tag == "Coins")
{
coins++;
score.text = coins + "";
Destroy(collider2d.gameObject);
audioSource.clip = Coin;
audioSource.Play();
}
else if (collider2d.tag == "deadzone")
{
Application.Loadlevel("level1");
}
else if (collider2d.tag == "Finish")
{
gameObject.rigidbody2D.isKinematic=true;
audioSource.clip = Win;
audioSource.Play();
}
}
↧