Na FreeHostingu Endora běží desítky tisíc webů. Přidejte se ještě dnes!
Vytvořit web zdarmaNa FreeHostingu Endora běží desítky tisíc webů. Přidejte se ještě dnes!
Vytvořit web zdarmavoid Update () { float xPos = transform.position.x + (Input.GetAxis("Horizontal") * paddleSpeed); playerPos = new Vector3 (Mathf.Clamp (xPos, -13f, 13), -9.5f, 0f); transform.position = playerPos; }Lerp(float a, float b, float t)) t je v rozsahu 0-1(0 až 100% mezi a b).
public class lerppokus : MonoBehaviour { public float minimum = 0.0F; public float maximum = 20.0F; void Update() { transform.position = new Vector3(Mathf.Lerp(minimum, maximum, Time.time), 0, 0); } }Zpozdí od spuštění podle hodnoty odkdy.
public float start=0f;
public float konec=180f;
public float odkdy = 1.0f;
public float rychlost;
void Update()
{
float lerpHodnota = Mathf.Lerp(start, konec, (Time.time - odkdy) * rychlost);
transform.eulerAngles = new Vector3(0,lerpHodnota, 0);
}
Když lerpHodnota klesne pod toleranci zastaví dopočítávání.
public float konec = 20f; public float rychlost; //od 0 do 1 public float tolerance = 0.1f; void FixedUpdate() { if (transform.position.x != konec) { float lerpHodnota = Mathf.Lerp(transform.position.x, konec, rychlost); if (konec - lerpHodnota < tolerance) { lerpHodnota = konec; } transform.position = new Vector3(lerpHodnota, 0, 0); } }MoveTowards(float aktuálníHodnota, float cílováHodnota, float přírůstek)
AktualniHodnota = Mathf.MoveTowards(AktualniHodnota,cilovaHodnota, prirustek * Time.deltaTime);
transform.localScale = new Vector3(1, AktualniHodnota, 1);
PerlinNoise(float x, float y)Používá se pro efekty textury, ale také pro animaci, generování výškových map terénu a mnoho dalších věcí.
public float value = 5;
private Vector3 offset;
void Start()
{
offset = new Vector3(Random.Range(-1, 10), Random.Range(-1, 10), Random.Range(-1, 10));
}
void Update()
{
float sampleX = Mathf.PerlinNoise(Time.time / value, offset.x);
float sampleY = Mathf.PerlinNoise(Time.time, offset.y);
float sampleZ = Mathf.PerlinNoise(Time.time * value, offset.z);
Camera.main.backgroundColor = new Color(sampleX, sampleY, sampleZ);
}
Změna pozice:
public float heightScale = 1.0F; public float xScale = 1.0F; void Update() { float height = heightScale * Mathf.PerlinNoise( Time.time * xScale, 0.0F); Vector3 pos = transform.position; pos.y = height; transform.position = pos; }Generování terénu:
public int depth=20; public int width=256; public int height=256; public float scale = 20f; public float offsetX = 100f; public float offsetY = 100f; void Start() { offsetX = Random.Range(0f, 9999f); offsetY = Random.Range(0f, 9999f); } void Update () { Terrain terrain = GetComponent<Terrain>(); terrain.terrainData = GenerateTerrain(terrain.terrainData); offsetX += Time.deltaTime * 5f;//terén teče } TerrainData GenerateTerrain(TerrainData terrainData) { terrainData.heightmapResolution = width + 1; terrainData.size = new Vector3(width, depth, height); terrainData.SetHeights(0, 0, GenerateHeights()); return terrainData; } float[,] GenerateHeights() { float[,] heights = new float[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { heights[x, y] = CalculateHeight(x, y); } } return heights; } float CalculateHeight( int x, int y) { float xCoord =( float) x / width * scale+offsetX; float yCoord = ( float)y / width * scale+offsetY; return Mathf.PerlinNoise(xCoord, yCoord); }Vlnění PLANE:
public float perlinScale; public float waveSpeed; public float waveHeight; public float offset; void Update() { CalcNoise(); } void CalcNoise() { MeshFilter mF = GetComponent<MeshFilter>(); MeshCollider mC = GetComponent<MeshCollider>(); mC.sharedMesh = mF.mesh; Vector3[] verts = mF.mesh.vertices; for (int i = 0; i < verts.Length; i++) { float pX = (verts[i].x * perlinScale) + (Time.timeSinceLevelLoad * waveSpeed) + offset; float pZ = (verts[i].z * perlinScale) + (Time.timeSinceLevelLoad * waveSpeed) + offset; verts[i].y = Mathf.PerlinNoise(pX, pZ) * waveHeight; } mF.mesh.vertices = verts; mF.mesh.RecalculateNormals(); mF.mesh.RecalculateBounds(); }