I need some help . I work at a 2d unity game which have a fluffy ball as the main character . This fluffy ball have a hand component ( child ) which have a animation . Each individual frame have a box collider property .This hand will be activated when i press E and that animation will start in the direction where my cursor is . So , the problem is next : I want that hand to grab stuffs . Like a box . Here i ask for your help . i tried to figure out how i can freeze the aniamation for a short time , like 5 seconds or till i press again E , when the box collider of that specific frame collide with a object (e.g. ground or box ).Here is the script of the hand :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class facingScript : MonoBehaviour
{
private SpriteRenderer render;
private Camera mainCam;
private Vector3 mousePos;
private Animator aniHand;
public bool freezeAniamtion = false;
void Start()
{
render = GetComponent<SpriteRenderer>();
mainCam = Camera.main;
gameObject.SetActive(false);
aniHand = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
mousePos = Input.mousePosition;
mousePos = mainCam.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, mainCam.transform.position.z - transform.position.z));
Vector3 rotation = mousePos - transform.position;
if(rotation.x > 0)
render.flipY = true;
else
render.flipY = false;
if(Input.GetKeyDown(KeyCode.E))
{
aniHand.Play("CharacterHand");
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "box")
{
StartCoroutine(HandCollide());
// help pls :)
}
}
private IEnumerator HandCollide(float waitTime)
{
// idk what i should put here :P
}
}`
I try with aniHand.speed but it dont do nothing and with PlayInFixedTime but idk how it work
So . I fugire it out some how . I have another script that activate and dezactivate my hand for 1 second. And when I try to stop my animation în hand script it just turn of from that another script