Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Animation only works by changing parameter (beginner question)

Discussion in 'Scripting' started by mardi_nl, Aug 8, 2019.

  1. mardi_nl

    mardi_nl

    Joined:
    Jun 23, 2013
    Posts:
    7
    Hi, as the title says, beginner question.

    Problem: I am trying to make the walking animation for my character.
    Controls (using this guide http://unity.grogansoft.com/move-player-to-clicktouch-position/) and animations (my own made sprites) are setup and working by itself, just not when im trying to combine them.

    If i manually change the parameter in animations to a greater amount then setup in the transitions (which is .01) the animation starts playing.

    I have tried using google and this forum's search engine, its just kinda hard figuring out what to look for.
    Thanks in advance
     
  2. FlashMuller

    FlashMuller

    Joined:
    Sep 25, 2013
    Posts:
    282
    Post your code :)
     
  3. mardi_nl

    mardi_nl

    Joined:
    Jun 23, 2013
    Posts:
    7
    Thanks for your reply!

    Here you go:

    Code (CSharp):
    1. using UnityEngine;
    2. public class MoveToClickInput : MonoBehaviour
    3. {
    4. [SerializeField] Transform target;
    5. float speed = 6f;
    6. Vector2 targetPos;
    7. private void Start()
    8. {
    9.     targetPos = transform.position;
    10. }
    11. void Update ()
    12. {
    13.     if(Input.GetMouseButtonDown(0))
    14.     {
    15.         targetPos = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
    16.         target.position = targetPos;
    17.     }
    18.     if((Vector2)transform.position != targetPos)
    19.     {
    20.        transform.position = Vector2.MoveTowards(transform.position, targetPos, speed * Time.deltaTime);
    21.     }
    22. }
    23. }
     
  4. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    837
    mardi_nl likes this.
  5. mardi_nl

    mardi_nl

    Joined:
    Jun 23, 2013
    Posts:
    7
    Allright thank you very much, im gonna give it my best try!
     
  6. mardi_nl

    mardi_nl

    Joined:
    Jun 23, 2013
    Posts:
    7
    My result; With that link i came up with a fixedupdate to give float-parameter values for position and give bool-parameter values to see if the character is still walking or not. With this i can control the animation in a 4way direction.
    Maybe this helps someone else facing the same problem in the future.