Hi everybody,
I have an game object with a script attached. If I click the game object, it’s animation will play (it’s a puppet walking to the left). Now I want the puppet (game object) to walk to the left if I click another game object.
Is it possible to use the same code and attach it to the other game object and then tweak the code a bit? Or do I have to do this in a different way.
This is the code I use now. Thank you for answering!!!
using UnityEngine;
using System.Collections;
public class Walk : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Linecast(worldPos, worldPos);
if (null != hit && hit.collider.gameObject == gameObject)
{
Animator anim = GetComponent<Animator>();
if (null != anim)
{
Debug.Log("Playing Lopen");
anim.Play("Lopen");
}
}
}
}
}
,