V
V
vovka_losira2020-06-26 15:35:05
C++ / C#
vovka_losira, 2020-06-26 15:35:05

Why is Vector3 zeroed out?

I can't figure out why my Vector3 _spownPos is set to zero.
In Start, it is set normally and produces the correct values, and in the void Create_archer() itself, it is set to zero (
What is my mistake?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Photon.Pun;
using Photon.Realtime;

public class Army : MonoBehaviourPun
{
    [Header("Cost")]
    private int _archerCost = 10;
    private int _preastCost = 10;
    private int _shieldCost = 10; 
    private int _spearCost = 10;
    private int _swordCost = 10;

    public GameObject _archerPrefab;
    public GameObject _shieldPrefab;
    public GameObject _preastPrefab;
    public GameObject _spearPrefab;
    public GameObject _swordPrefab;
    public Transform _army;
    private TokenCounter _tokenCounter;

    private GameObject _healthbar;

    public float _hp = 0f;
    public int _amount = 0;
    public List<GameObject> _soldiers = new List<GameObject>();


    private Vector3 _spownPos;

    private void Start()
    {
        _tokenCounter = GameObject.FindGameObjectWithTag("Token counter").GetComponent<TokenCounter>();
        _healthbar = GameObject.FindGameObjectWithTag("Healthbar");

        GameObject[] _spownPos_s = GameObject.FindGameObjectsWithTag("Spown");

        

        for (int i = 0; i < _spownPos_s.Length; i++)
        {
            if (_spownPos_s[i].GetPhotonView().IsMine)
            {
                _spownPos = _spownPos_s[i].transform.position;
                Debug.Log(string.Format("Позиция создания = {0}", _spownPos));
                
            } 
        }

        Debug.Log(string.Format("Позиция создания 2 = {0}", _spownPos));
    }



    private void Update()
    {
        
        
    }
    //Проверка PhotonNetwork.Instantiate
    public void Create_archer ()
    {
        Debug.Log(string.Format("Позиция создания 3 = {0}", _spownPos));

        if (_tokenCounter._tokens >= _archerCost)
        {
            
            GameObject _newSoldier = PhotonNetwork.Instantiate(_archerPrefab.name, _spownPos, Quaternion.identity);
            _soldiers.Add(_newSoldier);

            ArcherScript _soldier = _newSoldier.GetComponent<ArcherScript>();
            
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question