Hello,
I’m in the middle of creating a (2D) game and my object keeps switching to Z-11
I have code in which it should not do this
void Update()
{
//Other bits of code that don't even cause this (I checked)
player.transform.position = new Vector3(player.transform.position.x, player.transform.position.y, 1.0f);
}
Anybody know what is going on?

Also, I used Debug.Log for the position, it’s showing 1.0, but not on the transform???

2 Answers
2
Ignore spaghetti code and comments, my way of getting code I don’t know is to try and find forum posts that help
Scripts that are connected to certain object:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class size : MonoBehaviour
{
public GameObject player;
public Vector3 blankVector3;
public GameObject button;
public bool clicked;
// Start is called before the first frame update
void Awake()
{
blankVector3 = new Vector3(0f, 0f, 0f);
Move();
}
public void Move()
{
Debug.Log(Screen.width * -1f / 100f / 2f);
Debug.Log(Screen.width / 100f / 2f);
Debug.Log(Screen.height * -1f / 100f / 2f);
Debug.Log(Screen.height / 100f / 2f);
player.transform.position = new Vector3(Random.Range(Screen.width * -1f / 100f / 2f, Screen.width / 100f / 2f), Random.Range(Screen.height * -1f / 100f / 2f, Screen.height / 100f / 2f), 1.0f);
Debug.Log(player.transform.position);
}
public void Sizedown()
{
player.transform.localScale = player.transform.localScale - new Vector3(0.05f, 0.05f, 0f);
button.transform.localScale = button.transform.localScale - new Vector3(0.05f, 0.05f, 0f);
}
void Start()
{
}
// Update is called once per frame
void Update()
{
player.transform.position = new Vector3(player.transform.position.x, player.transform.position.y, 1.0f);
if (clicked == false)
/{
//player.transform.localScale = player.transform.localScale + new Vector3(0.05f, 0.05f, 0f);
}
if (player.transform.localScale.x <= blankVector3.x || player.transform.localScale.y <= blankVector3.y)
{
player.transform.localScale = new Vector3(0.01f, 0.01f, 1f);
button.transform.localScale = new Vector3(0.01f, 0.01f, 1f);
Move();
}
}
}
Script #2:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lhide : MonoBehaviour
{
public GameObject panel;
public GameObject tutorialL;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("l"))
{
if (panel.activeSelf == true)
{
panel.SetActive(false);
tutorialL.SetActive(false);
}
else
{
panel.SetActive(true);
}
}
}
}
Scripts that mention that gameobject:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class hit : MonoBehaviour
{
public bool hits;
public GameObject capital;
public GameObject earthquake;
void OnCollisionEnter2D(Collision2D collision)
{
//Check for a match with the specified name on any GameObject that collides with your GameObject
if (collision.gameObject.name == "earthquake")
{
//If the GameObject's name matches the one you suggest, output this message in the console
Debug.Log("Do something here");
hits = true;
}
else
{
hits = false;
}
//Check for a match with the specific tag on any GameObject that collides with your GameObject
if (collision.gameObject.tag == "earthquake")
{
//If the GameObject has the same tag as specified, output this message in the console
Debug.Log("Do something else here");
}
}
}
//Detect collisions between the GameObjects with Colliders attached
(not really) Script 2:
Unity OnClick() tab in the inspector:
Sizedown();
Those are all the scripts that are in or mention that object.
Using a wonderful way called comments, i found out it is in the code I provided
player.transform.position = new Vector3(player.transform.position.x, player.transform.position.y, 1.0f);
More specifically, this part.
Edit: apparently this is only for forcing it to -11, not setting and forcing.
Edit #2: …you mean i could have used transform.position.player.z this whole time…
The issue doesn't appear to be in this line of code- what is the full code?
– anon36725143