- Home /
Whers should i use this code template?
I was looking through the auto code templates and i found this so i tries using it to crouch my character.
public PC_Control (bool isCrouching)
{
this.isCrouching = isCrouching;
}
bool Crouch(){
return isCrouching;
}
Ive been trying to get it working but im not sure what im doing. I wanted to learn a few new things today and this is one of them. I tried looking on the internet but the examples are a little bit alien to me.
My initial goal is to make my character crouch with the s key and then stand up again when i let go of the s key.
Answer by Anxo · Oct 24, 2014 at 04:44 PM
Hi,
I think you may be better off starting on this page. http://unity3d.com/learn/tutorials/modules/beginner/scripting
I recommend doing ALL of the beginner tutorials before actually attempting to create something as you may just end in frustration or give up on your project. It only takes a little while and will give you a good understanding of most of the things you need.
As to your question, First, your code does not work. You have a public PC_Control, so you would have to have a class called PC_Control but you are returning a bool "return isCrouching that you are passing into the method.
If you have an animation of your character or a bool you want to set for your character to crouch you could use something along the lines of.
if(Input.GetKeyDown(KeyCode.S)){
Debug.Log("Crouch Code here");
}
if(Input.GetKeyUp(KeyCode.S)){
Debug.Log("Stand Up Here");
}
But again, I would recommend getting your understanding of the fundamentals up to speed first so you give yourself the power to do the things you want to do.
Your answer
