what is wrong with my C# code?
i am trying to make my sliderjoint2d motor go left to its limits then right to its limits but i keep getting an error over "slider.motor" in "slider.motor.motorSpeed=1.5f;" telling me that I "Cannot modify the return value of 'SliderJoint2D.motor' because it is not a variable"
using UnityEngine; using System.Collections;
public class SliderScr3 : MonoBehaviour { public SliderJoint2D slider;
// Use this for initialization
void Awake()
{
slider = this.gameObject.GetComponent<SliderJoint2D>();
}
void Start () {
if (slider.jointTranslation == -2)
{
slider.motor.motorSpeed=1.5f;//make motor go right for optional shooting
}
}
// Update is called once per frame
void Update () {
}
}
Answer by BabilinApps · Oct 03, 2015 at 10:49 PM
you have to store the motor. This means add a variable called " JointMotor2D" Then you can change the value.
if (slider.jointTranslation == -2)
{
JointMotor2D _motor = slider.motor;
_motor.motorSpeed=1.5f; //make motor go right for optional shooting
}
Your answer
Follow this Question
Related Questions
how to change color of that part of slider before the handle,not the fill part 2 Answers
How to make a cleaning effect similar to the one in dumb ways to die? 0 Answers
Turning on an option with GPS 0 Answers
Where can I place a flag/bool to suspend the entire game loop in Unity? 0 Answers
How to check if player is rapidly rotating the joystick? 2 Answers