(26,47): error CS1525: Unexpected symbol `)'
I was trying to script an object to move to a different position when the player presses the right button, i based it off of integers because the script would be attached to multiple objects with different set locations. The script basically increases the integer when the right button is pressed and that integer changes the object to its next position based off of that integer. I could also use help giving the integer a range of 1 to 4. I keep getting (26,47): error CS1525: Unexpected symbol `)' and also one on line (31,47)
using System.Collections;
public class menugun : MonoBehaviour {
public int position;
public Vector3 startPosition;
public Vector3 secondPosition;
public Vector3 thirdPosition;
public Vector3 fourthPosition;
public Animator anim;
public Button rightArrow;
public Button leftArrow;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
rightArrow = rightArrow.GetComponent<Button> ();
leftArrow = leftArrow.GetComponent<Button> ();
position = 0;
}
void RightPress()
{
anim.SetInteger("position", ++);
}
void LeftPress()
{
anim.SetInteger("position", +-);
}
void Update ()
{
if (position = 0)
{
transform.localPosition = startPosition;
}
if (position = 1)
{
transform.localPosition = secondPosition;
}
if (position = 2)
{
transform.localPosition = thirdPosition;
}
if (position = 3)
{
transform.localPosition = fourthPosition;
}
}
}
Answer by Namey5 · Sep 13, 2016 at 06:55 AM
Well, if you are doing a comparison you shouldn't be setting values.
Should be
if (position == 0)
Rather than
if (position = 0)
And I'm not particularly sure if you can assign an increment to a function. You may be able to, but I would do it;
int animPos = 0;
void RightPress()
{
animPos++;
}
void LeftPress()
{
animPos--;
}
void Update ()
{
animPos = Mathf.Clamp (animPos, 1, 4); //Will set a range for the int from 1 to 4
anim.SetInteger ("position", animPos);
}