Closed RotX18 closed 2 years ago
Logic is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Key : MonoBehaviour, IPickable
{
#region PUBLIC VARS
public Animator anim;
public GameObject door;
#endregion
#region PRIVATE VARS
private bool _unlock = false;
private int _doorUnlock = Animator.StringToHash("DoorUnlock");
#endregion
#region PROPERTIES
#region IPickable PROPERTIES
public IPickable.Controller CurrentController {
get;
set;
}
public bool Grabbed {
get;
set;
} = false;
#endregion
public bool Unlock {
get {
return _unlock;
}
set {
_unlock = value;
}
}
#endregion
#region INTERFACE METHODS
public void OnRelease(){
if(_unlock && !Grabbed){
gameObject.transform.SetParent(door.transform);
anim.SetTrigger(_doorUnlock);
}
}
#endregion
}
Description: Key implements IPickable to facilitate unlocking animation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorLock : MonoBehaviour
{
private void OnTriggerEnter(Collider other) {
if(other.name.Equals("Key")){
other.GetComponent<Key>().Unlock = true;
}
}
}
Description:
Animation is bugged; Key does not animate when animation is triggered, to discuss with @RabbitKazma before updating issue and closing
Implemented suggestion by @RabbitKazma to use a pre-parented key to run the animation
#region INTERFACE METHODS
public void OnRelease(){
if(_unlock){
Destroy(gameObject);
}
}
private void OnDestroy() {
Debug.Log("PLAYING DOOR ANIM");
anim.SetTrigger(_doorUnlock);
}
#endregion
Edits:
Feature completed, issue will now be closed
Credits
Animations and interaction of the objects were done with this issue by @RotX18
Objective: