46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using UnityEngine;
|
|
using Unity.Mathematics;
|
|
|
|
public class sitebg : MonoBehaviour
|
|
{
|
|
public GameObject Player;
|
|
public Sprite[] Skins;
|
|
public Sprite[] Face;
|
|
SpriteRenderer PFace;
|
|
SpriteRenderer PSkin;
|
|
int speed;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
PFace = Player.GetComponentsInChildren<SpriteRenderer>()[0];
|
|
PSkin = Player.GetComponentsInChildren<SpriteRenderer>()[1];
|
|
Spawn();
|
|
InvokeRepeating("SetSpeed", 0, 0.5f);
|
|
}
|
|
|
|
void Spawn()
|
|
{
|
|
int r = UnityEngine.Random.Range(0,64);
|
|
print(r);
|
|
PFace.sprite = Face[r];
|
|
PSkin.sprite = Skins[r];
|
|
int r2 = UnityEngine.Random.Range(-5, 5);
|
|
Player.transform.GetChild(0).transform.position = new Vector3(r2, 10, 0);
|
|
Player.transform.GetChild(1).transform.position = new Vector3(r2, 10, 0);
|
|
Player.GetComponentInChildren<Rigidbody2D>().linearVelocity = new Vector2(0,0);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate()
|
|
{
|
|
if(Player.transform.GetChild(0).transform.position.y < -10)
|
|
{Spawn();}
|
|
Player.GetComponentInChildren<Rigidbody2D>().linearVelocity = new Vector2(speed * 7, Player.GetComponentInChildren<Rigidbody2D>().linearVelocity.y);
|
|
}
|
|
|
|
void SetSpeed()
|
|
{
|
|
speed = UnityEngine.Random.Range(-1,2);
|
|
print(speed);
|
|
}
|
|
}
|