Skip to content

Commit

Permalink
Ajout du changement du sprite du lumberjack en fonction de son mouvem…
Browse files Browse the repository at this point in the history
…ent. Pas d'utilisation d'animator vu qu'il n'y a qu'une frame par action
  • Loading branch information
LucasBeltrame committed May 1, 2016
1 parent ff212a2 commit 835ef8b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Binary file modified Assets/Scenes/Level1.unity
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Scripts/FollowObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void Update()
if (target)
{
Vector3 point = GetComponent<Camera>().WorldToViewportPoint(target.position);
Vector3 delta = target.position - GetComponent<Camera>().ViewportToWorldPoint(new Vector3(0.5f,0.09f, point.z)); //(new Vector3(0.5, 0.5, point.z));
Vector3 delta = target.position - GetComponent<Camera>().ViewportToWorldPoint(new Vector3(0.5f,0.08f, point.z)); //(new Vector3(0.5, 0.5, point.z));
Vector3 destination = transform.position + delta;
transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
}
Expand Down
9 changes: 9 additions & 0 deletions Assets/Scripts/Lumberjack/LumberjackMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class LumberjackMovement : MonoBehaviour {
private float movex = 0f;
public bool moveBackground = true;

public Sprite movingSprite;
public Sprite idleSprite;

// Use this for initialization
void Start () {
body = GetComponent<Rigidbody2D>();
Expand All @@ -35,10 +38,16 @@ void Update ()
if(movex > 0)
{
this.GetComponent<SpriteRenderer>().flipX = true;
this.GetComponent<SpriteRenderer>().sprite = movingSprite;
}
else if(movex < 0)
{
this.GetComponent<SpriteRenderer>().flipX = false;
this.GetComponent<SpriteRenderer>().sprite = movingSprite;
}
else
{
this.GetComponent<SpriteRenderer>().sprite = idleSprite;
}
}
}

0 comments on commit 835ef8b

Please sign in to comment.