- Home /
C# Crouch script problem
I'm trying to get my First Person Controller to "crouch" with this script, and I am getting some big errors. Apparently Player.transform.position.y and Player.transform.localScale.y are not variables that I can set. Does anybody know the proper syntax of what I am trying to access and alter? Here is the code:
1 public void Update()
2 {
3 if(Input.GetButtonDown("Crouch"))
4 {
5 Player.transform.position.y -= .5;
6 Player.transform.localScale.y -= .5;
7 Crouch = true;
8 }
9 }
Answer by Chris D · Aug 09, 2011 at 05:55 PM
If you take a look at the scripting docs, you'll see that there are a number of instances where you can't directly alter values in C#. Instead, you have to create a temporary variable, usually just in the assignment, that will be used to modify the current value. It's strange (to me) and I'm not exactly sure what the rule is, but it's there.
Instead of
Player.transform.localScale.y -= .5;
try
Player.transform.localScale -= new Vector3(0,.5F,0);
Sweet! Thank you, there is still a bit of an issue, but I think I can take it form here. (:
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
First person Controller auto movement 0 Answers
C# How to have a gun select 1 Answer