- Home /
Canvas & Player spawning
Hey guys, I'm working on a multiplayer game, I have everything working.
But the Canvas is weird to work with..
I have each player spawn with a Canvas, etc. Well, When I spawn the player, he has to be at rotation of 0, but what if I want to spawn the player at a different angle. I mean nobody always wants to spawn in the same direction no matter what team you are.
Is there any way to spawn player and have the canvas rotate to the direction the play spawns?
Answer by TonyLi · Jan 06, 2015 at 05:49 PM
If it's a world-space canvas childed to the player GameObject, it should automatically match rotation. Otherwise add a script like this:
using UnityEngine;
public class MatchRotation : MonoBehaviour {
public Transform player;
public Transform canvas;
void OnStart() {
canvas.rotation = player.rotation;
}
}
You'll need to assign player and canvas. Or put it on one of the GameObjects and use that GameObject's transform in place of player or canvas.
I see it work for like a split second, then it just disappears :(.
I guess it goes back to where it was before.
I got it, I had to add it in the Update function.... Wish I didn't have to do it that way.
Unless there is another way?
I depends on what you need it to do. Can you make the canvas a child of the player GameObject? Then you don't need to use any scripts.
Otherwise, if the player can rotate during gameplay and you want the canvas to rotate along with it, you'll need to use Update().
I tried making it a child that's how I was doing it before... It would only work if I spawned in the direction that the Canvas was originally placed.
I guess I'll do it in the Update Function. I mean it's just one single line, it shouldn't cause a lot of overhead with 30 players.
But I'll mark Answer as correct, as it is correct.
Thank you so much for your help! Can't believe I didn't think about it! lol.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
4.6 UI Canvas is smaller than normal 1 Answer
Random spawning papers, plus GUI texture book help. 0 Answers
Display Bullets Left on Screen 1 Answer
Not working gui buttons 1 Answer