- Home /
How can I change rotation of spawning platforms?(platforms must appear at angles of -45 degrees Y),How can change rotation of platforms? (plantforms must appear at angles of -45 degrees Y)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawnplatforms : MonoBehaviour
{
public GameObject platform;
private GameObject platforminst;
private Vector3 platformpos;
private float speed = 5f;
void Start()
{
platformpos = new Vector3 (Random.Range(0.93f, 1.74f), Random.Range (2.18f,-3.36f),0f);
platforminst = Instantiate(platform, new Vector3(5f, -6f, 0f), Quaternion.identity) as GameObject;
platforminst.transform.localScale = new Vector3(Random.Range(1.2f, 2f) , platforminst.transform.localScale.y, platforminst.transform.localScale.z);
platform.transform.localRotation = // *what I must write?*
}
void Update()
{
if (platforminst.transform.position != platformpos)
platforminst.transform.position = Vector3.MoveTowards(platforminst.transform.position, platformpos, Time.deltaTime * speed);
}
}
, using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Spawnplatforms : MonoBehaviour
{
public GameObject platform;
private GameObject platforminst;
private Vector3 platformpos;
private float speed = 5f;
void Start()
{
platformpos = new Vector3 (Random.Range(0.93f, 1.74f), Random.Range (2.18f,-3.36f),0f);
platforminst = Instantiate(platform, new Vector3(5f, -6f, 0f), Quaternion.identity) as GameObject;
platforminst.transform.localScale = new Vector3(Random.Range(1.2f, 2f) , platforminst.transform.localScale.y, platforminst.transform.localScale.z);
platform.transform.localRotation = //*what I must write?*
}
void Update()
{
if (platforminst.transform.position != platformpos)
platforminst.transform.position = Vector3.MoveTowards(platforminst.transform.position, platformpos, Time.deltaTime * speed);
}
}
Answer by Felipe669 · Jan 02, 2020 at 02:35 PM
Hey there!
At the Instantiate method, try using "Quaternion.Euler(0, -45, 0)", instead of "Quaternion.identity".
And you can also remove this line:
"platform.transform.localRotation = // what I must write?"
That should spawn the object at -45 degrees on the Y axis.
(But if you're making a 2D game, you probably want to rotate around the Z axis instead.)
Hope it helps!
Your answer
Follow this Question
Related Questions
How can I change rotation of spawning platforms?(platforms must appear at angles of -45 degrees Y) 1 Answer
2.5D platformer camera 0 Answers
How To Change Player As Soon as He Take Powerup 1 Answer
URGENT!!! Not able to slice in the sprite editor 2 Answers
Hi I am making a 2D game and I am having problem with this script: 1 Answer