Hi YRO,
First of all, please do not apologise for asking questions. Asking questions is a crucial part of everybody’s learning process, and we all are learning here. Even Rick is still learning. Every good programmer is always learning new things because technology constantly evolves.
Secondly, it would be great if you could post your code as formatted text because screenshots are difficult to read, and we cannot copy and paste any lines from pictures.
Thirdly, where is the turbo
variable declared? According to your screenshot, there is a local turbo
variable declared und the MovePlayer method. The OnCollisionEnter method cannot access that variable because that variable does not exist within the same scope of the OnCollisionEnter method. Since I cannot see the rest of your code, I don’t know if you also have an instance variable named turbo
, which can be found at the top of your class.
Apart from the issue with the scope, your code looks fine and should, theoretically, work once you put the turbo
variable at the top of your class.
See also: