Latest Update!
I have been working on this from time to time trying to get ladders, combat and other things to work well together. I am noticing that certain elements are not working well together. For example, inventory, store and health UI are not working as individuals but as whole. If the player adds damage to an enemy, the player also gets damage. I thought at first that the scripts were using to much of the same code so I changed that. Still the player was receiving damage. Removed enemy attack and again still draining player health. Also noticed that the player can just run into the enemy and it will lose health, no sword needed. It is certain I am missing something. For now I will stop with this and come back to it.
Next problem I am seeing is that fact that controlling both the inventory and store UI are not working. I wanted something similar to that of the Witcher 3 and WOW. Seems I have missed something here as well. I looked at several tutorials on inventory, but I am not seeing my issues in those tutorials. Is it possible to have more than one eventsystems? Could this be my issues? I will remove this element for now and come back to this as well.
Now for my latest update. I have managed to get a working ladder script. I say working because that is pretty much all it does. I am able to move up and down with animations, but the player does not face the ladder when climbing. I could set it as a target transform, but not been able to do so.
Also having trouble with the fact that the player will drop if it stops. Meaning if going up and the button is released the player drops down to the ground. Also having trouble with the animations. I want the player only to animate when the button is pressed. I am guessing I need to SetFloat instead of SetBool. Any help would be great.
Here are my ladder scripts. If anyone can help with the refinement of the two scripts would be much appreciated. Not asking for a hand out, just a pointer. I can do the leg work.
This is attached to the player.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;
public class Ladder : MonoBehaviour
{
public GameObject go;
public float speed = 10f;
public bool isClimbing;
public Rigidbody m_Rigidbody;
public float exit = 0.1f;
void Start()
{
m_Rigidbody = GetComponent<Rigidbody>();
}
void Update ()
{
if(isClimbing)
{
go.GetComponent<ThirdPersonUserControl>().enabled = false;
go.GetComponent<ThirdPersonCharacter>().enabled = false;
m_Rigidbody.useGravity = false;
float v = Input.GetAxis("Vertical");
if(v !=0)
{
go.transform.Translate(Vector3.up * v * speed * Time.deltaTime);
}
}
else
{
go.GetComponent<ThirdPersonUserControl>().enabled = true;
go.GetComponent<ThirdPersonCharacter>().enabled = true;
m_Rigidbody.useGravity = true;
}
}
void OnTriggerExit(Collider Col)
{
if(Col.gameObject.tag == "Ladder")
{
transform.Translate(Vector3.forward * exit);
}
}
}
This is attached to the trigger.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LadderTrigger : MonoBehaviour
{
public Ladder climb;
public Animator anim;
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
climb.isClimbing = true;
anim.SetBool("Climb", true);
}
}
void OnTriggerExit(Collider other)
{
if(other.tag == "Player")
{
climb.isClimbing = false;
anim.SetBool("Climb", false);
}
}
}
Little video if what the ladder script is doing.