can't seem to find answers related to this, there's some questions up but no answers to them.
again, i'm a game artist, starting out to learn to script, so i'm looking for help, and best if i get pointed in the right direction and where to look and what to look at to solve my current problem.
after writing my code (i'm trying! learning alot already, coming from zero c# background), i am now getting this error:
Assets/Booster.cs(34,27): error CS1955: The member `UnityEngine.ConstantForce.force' cannot be used as method or delegatecannot be used as method or delegate
here's what i have so far written:
using UnityEngine;
using System.Collections;
public class Booster : MonoBehaviour {
//private vehicle = GameObject.Find("vehicle"); //obtain a reference to the object with the script attached
//private constantForce = vehicle.GetComponent<engine>(); //obtain a reference to the script itself
//private currentSpeed = constantForce.force; //copy the value of the life variable to a local variable
public GameObject target;
// Update is called once per frame
void Update () {
}
void OnTriggerEnter () {
Boost();
StartCoroutine(Slowdown());
}
private void Boost(){
//Engine e = target.GetComponent<Engine>();
//You don't need a cast, that the whole point of generics.
//I don't think you need this either.
ConstantForce motor = target.GetComponent<ConstantForce>();
//You needed an instance.
motor.force = Vector3.forward * 500;
//Hard-coded values are generally not good.
}
IEnumerator Slowdown(){
ConstantForce motor = target.GetComponent<ConstantForce>();
yield return new WaitForSeconds(5);
if (motor.force ("0")){
motor.force = Vector3.forward * -250;
}
}
}
my error above is after i tried adding the "if" statement at the Slowdown function. I'm trying to make it check to make sure the object does not get pushed backwards into the "negative velocity" which makes it travel in reverse. like it's going from 10, to 0, then to -10. i don't want it to go down past 0 into "reverse".
the best thing now is if i'm able to write it so that it returns to it's original velocity, prior to "slowdown". like it's traversing at say 1000 before my Boost function, after the Boost function i want to slow it back down to the original speed after a certain period of time.
big thanks to anyone that helps!