I´m working on a game where the player has to solve some puzzles by moving boxes around, He has to grab(hold) them and place at the right place.
I have my character moving around(3rd person), he moves forward, backwards and strafes to both sides, the mouse controls the camera like in World of Warcraft.
What i need to know now is how can i make it grab the box by pressing a button and move it around with him, only releasing the box when i release that button. Thanks
Doesn’t work tho…I get the error “Cannot inplicitly convert type ‘UnityEngine.GameObject’ to’UnityEngine.Transform’”…
And I also wanted the code to be on my player(otherwise I’ll have to add the script to every single box…and there will be many), but I couldn’t find a way to get it to work.
Thats my player script:
using UnityEngine;
class Move : MonoBehaviour // Sempre que houver a necessidade de mexer na cena tem de herdar a classe MonoBehavior
{
public int vel = 5; // Se não colocar nada o programa entende a variavel como privada
public Transform spawPoint;
public Transform focoVisao;
public void Update()
{
//transform.LookAt(focoVisao);
transform.Translate(vel * Time.deltaTime * Input.GetAxis("Horizontal"), 0, vel * Time.deltaTime * Input.GetAxis("Vertical")); // Time.deltaTima representa o tempo de resposta entre os frames
}
public void OnCollisionEnter(Collision hit)
{
if(hit.gameObject.tag == "rochas")
{
transform.position = spawPoint.position;
}
}
}
I’m still trying to find a way to solve the “LookAt” problem (so it doesn’t move on the Y axis)… help pls
Thanks @syclamoth, unfortuntelly I don’t have enough knowledge on C# to write that code, could you please help me with some? I’ve been trying to make it work for a long time and can’t get it =/…Can you help me with some code pls? or point me to somewhere where i can learn about it. Usually stuff I find is a bit hard to understand as I don’t know much about C# yet. Thanks