- Home /
Having trouble with player.transform
I've spent over 2 hours going over this and I can't seem to find what is wrong with my coding. For some reason it just won't move the player. This is my coding (a lot of stuff that I don't really think is causing the problem, the real problem is at the ending):
using UnityEngine;
using System.Collections;
public class Level : MonoBehaviour {
private int levelWidth;
private int levelHeight;
public Transform grassTile;
public Transform stoneBrickTile;
private Color[] tileColors;
public Color grassColor;
public Color stoneBrickColor;
public Color spawnPointColor;
public Texture2D levelTexture;
public Entity player;
void Start () {
levelWidth = levelTexture.width;
levelHeight = levelTexture.height;
loadLevel();
}
void Update () {
}
void loadLevel()
{
tileColors = new Color[levelWidth * levelHeight];
tileColors = levelTexture.GetPixels ();
for(int y = 0; y < levelHeight; y++)
{
for(int x = 0; x < levelWidth; x++)
{
if(tileColors[x+y*levelWidth] == grassColor)
{
Instantiate(grassTile, new Vector3(x, y), Quaternion.identity);
}
if(tileColors[x+y*levelWidth] == stoneBrickColor)
{
Instantiate(stoneBrickTile, new Vector3(x, y), Quaternion.identity);
}
if(tileColors[x+y*levelWidth] == spawnPointColor)
{
Instantiate(grassTile, new Vector3(x, y), Quaternion.identity);
Vector3 pos = new Vector3(x, y);
player.transform.position = pos;
}
}
}
}
}
I've replaced the grassTile with other tiles just to see if it replaces it like it should and it does. It just doesn't want to put my character there.
Answer by gribbly · Oct 29, 2014 at 01:37 AM
The only thing that looks suspicious is that player is of type "Entity". That's not a standard type in Unity, is it? Why isn't player a GameObject or a Transform?
Your answer
![](https://koobas.hobune.stream/wayback/20220613170210im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to make a player die after health reaches 0 3 Answers
Player flies PROBLEM 1 Answer
How do I make my Game Object face the direction it's going? 3 Answers
iTween Visual Editor Event Call from C# to Javascript 1 Answer