error CS0118: `GameManager.Spikepole' is a `field' but a `type' was expected

I want to set Spikepole y Position, but error in 100 GameManager.Spikepole' is a field’ but a `type’ was expected, I want to fix it.

thanks!

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Text;

public class GameManager : MonoBehaviour {
    #region Inspecter Variables
    public GameObject HomeGroup;
    public GameObject ResultGroup;

    public GameObject TouchPanel;
    public GameObject Panda;
    public GameObject Spikepole;
    public Text PointText;
    #endregion

    [HideInInspector] public int GamePoint = 0;
    bool isGameAcive = false;
    static Vector2 jumpForce = new Vector2(0,14);
    static float spikepoleMoveValue = .05f;
    static float positionY = 0;
   
    void Start () {
        PrePareView ();
        EnableTouchPanel ();
    }

    void PrePareView()
    {
        HomeGroup.SetActive (true);
        Spikepole.GetComponent<Transform> ().localPosition = Vector3.right * 3;
    }

    public void StartGame()
    {
        isGameAcive = true;
        StartCoroutine ("SpikepoleMoving");
        HomeGroup.SetActive (false);
        ResultGroup.SetActive (false);
        Panda.GetComponent<Animator> ().enabled = isGameAcive;
    }

    public void EndGame()
    {
        isGameAcive = false;
        StopCoroutine ("SpikepoleMoving");
        ResultGroup.SetActive (true);
        Panda.GetComponent<Animator> ().enabled = isGameAcive;
    }

    void ResetGame()
    {
        GamePoint = 0;
        PointText.text = GamePoint.ToString ();
        HomeGroup.SetActive (false);
        ResultGroup.SetActive (false);
        Panda.GetComponent<Transform> ().localPosition = new Vector3 (-0.75f,-1.977f, 20);
        Spikepole.GetComponent<Transform> ().localPosition = Vector3.right * 3;
    }

    void EnableTouchPanel()
    {
        TouchPanel.SetActive (true);
    }

    void DisableTouchPanel()
    {
        TouchPanel.SetActive (false);
    }

    #region Input Events
    public void Jump()
    {
        if (!isGameAcive)
        {
            ResetGame ();
            StartGame ();
        }

        if (Panda.GetComponent<Panda> ().HasPandaJumpTwice)
            return;
       
        if (Panda.GetComponent<Panda> ().IsPandaJumping)
            Panda.GetComponent<Panda> ().HasPandaJumpTwice = true;
        else
            Panda.GetComponent<Panda> ().IsPandaJumping = true;

        Panda.GetComponent<Rigidbody2D> ().velocity = jumpForce;
    }
    #endregion

    IEnumerator SpikepoleMoving()
    {
        while(true)
        {
           
            if (Spikepole.GetComponent<Transform> ().localPosition.x < -5.5f)
            {
                positionY = Random.Range(-1.75f, 0.0f);
                //Spikepole Y = new Vector3(Vector3.right * 3, positionY, 0.0f);
                Spikepole.GetComponent<Transform>().localPosition = Vector3.right * 3;
                //Spikepole.GetComponent<Transform>().localPosition.y = Y;
            }
           
            Spikepole.GetComponent<Transform> ().localPosition += Vector3.left * spikepoleMoveValue;
            yield return new WaitForEndOfFrame ();
        }
    }
}

public class GM{
    private static GameManager _gameManager = null;
    public static GameManager GameManager{
        get{
            if (_gameManager == null)
                _gameManager = GameObject.FindObjectOfType<GameManager> ();
            return _gameManager;
        }
    }
}

Try this:

Spikepole.transform.position = new Vector3(Vector3.right * 3, positionY, 0.0f); // the vector 3's x y and z coordinates will move the object "Spikepole"
1 Like

i change like this

if (Spikepole.GetComponent<Transform> ().localPosition.x < -5.5f)
            {
                positionY = Random.Range(-1.75f, 0.0f);
                //Spikepole Y = new Vector3(Vector3.right * 3, positionY, 0.0f);
                //Spikepole.GetComponent<Transform>().localPosition = Vector3.right * 3;
                Spikepole.transform.position = new Vector3(Vector3.right * 3, positionY, 0.0f);
                //Spikepole.GetComponent<Transform>().localPosition.y = Y;
               
            }

but error CS1502: The best overloaded method match for UnityEngine.Vector3.Vector3(float, float, float)' has some invalid arguments and error CS1503: Argument #1’ cannot convert UnityEngine.Vector3' expression to type float’
did I change wrong?

Line 6 above, you’re making a new Vector3 out of a Vector3 and two floats.

You want to make out of three floats.

You probably want to remove the Vector3.right * and leave the 3 for the first float argument.

1 Like

Oh wow I missed that :stuck_out_tongue:

1 Like

You also still have Spikepole.GetComponent<Transform> in that last code sample you added, in the first line.