- Home /
Compile Errors for Script
i get an parsing error on this:
using UnityEngine; using System.Collections;
public class MoveForwardwithMouseClick : MonoBehaviour {
void FixedUpdate() { if (Input.GetAxis("Fire1")) { rigidbody.AddForce(transform.forward rigidbody.velocity 2f); } }
Assets/Scripts/MoveForwardwithMouseClick.cs(11,1): error CS8025: Parsing error
i want to thurst a rigidbody forward to it's z-axis with an upwarding speed by pressing the left mouse button.
I closed the lines and get now other errors:
public class MoveForwardwithMouseClick : MonoBehaviour {
void FixedUpdate() {
if (Input.GetAxis("Fire1")) {
rigidbody.AddForce(transform.forward * rigidbody.velocity * 2f);
}
}
}
error CS0029: Cannot implicitly convert type float' to
bool'
error CS0019: Operator *' cannot be applied to operands of type
UnityEngine.Vector3' and `UnityEngine.Vector3'
O_O
It would be helpful if you pasted the actual error, since it usually tells you exactly what's wrong. That, or you don't have a closing }, I don't know if you just missed that when you pasted your script in here or not.
I think the missing closing '}' for the class is the error.
Answer by qJake · Aug 01, 2010 at 09:32 AM
Okay, two problems.
First: GetAxis returns a number, and you can't if(number).
if (Input.GetButton("Fire1"))
Second: You can't multiply two vectors together. I think you probably wanted this instead:
rigidbody.AddForce(transform.forward * 2f);
You don't need the velocity at all, since AddForce calculates the Dot Product for you, combining the vectors with physics magic. :)
Your answer
Follow this Question
Related Questions
Quiz Scoreboard 2 Answers
How do i rearrange this in C(sharp)? 0 Answers
Getting list music array 1 Answer
[Closed] Getting CS0029 error when I try to check position of an object 1 Answer
help with a random battle generator? 2 Answers