follower.transform.rotation = target.transform.rotation;
follower.transform.rotation = Quaternion.Euler(0, target.transform.eulerAngles.y, 0);
Vector3 flatForward = target.transform.forward;
flatForward.y = 0;
if (flatForward != Vector3.zero)
{
flatForward.Normalize();
follower.transform.rotation = Quaternion.LookRotation(flatForward);
}
// Создаём временную рендер-текстуру
var renderTexture = RenderTexture.GetTemporary(Screen.width, Screen.height);
// Рендерим в неё картинку с камеры
camera.targetTexture = renderTexture;
camera.Render();
var active = RenderTexture.active;
RenderTexture.active = renderTexture;
{
// Превращаем рендер-текстуру в Texture2D
var texture = new Texture2D(renderTexture.width, renderTexture.height);
texture.ReadPixels(new Rect(0, 0, texture.width, texture.height), 0, 0);
texture.Apply();
}
RenderTexture.active = active;
RenderTexture.ReleaseTemporary(renderTexture);
// Превращаем текстуру в файл с помощью Texture2D.EncodeToJPG или Texture2D.EncodeToPNG
// Сохраняем на диск
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof (LineRenderer))]
public class LineRendererTest : MonoBehaviour
{
public List<Transform> points = new List<Transform>();
private LineRenderer lineRenderer;
private void Awake()
{
lineRenderer = GetComponent<LineRenderer>();
}
private void Update()
{
for (int i = 0; i < points.Count; i++)
{
var point = points[i];
lineRenderer.SetPosition(i, point.position);
}
}
}
using System;
public class Test<T>
{
// Перед вызовом конструктора выставится в default(int), то есть 0
private int i;
// Для ссылочного типа default(object) будет null
private object obj;
// default(T)
private T t;
public Test()
{
// Не инициализированная переменная
int foo;
// error CS0165: Use of unassigned local variable 'foo'
Console.WriteLine(foo.ToString());
foo = 0;
// У foo появилось значение, теперь переменной можно пользоваться
Console.WriteLine(foo.ToString());
int bar;
// error CS0165: Use of unassigned local variable 'bar'
Ref(ref bar);
// Для ref нужна инициализированная переменная
Ref(ref foo);
// Для out не нужна
Out(out foo);
Out(out bar);
}
private void Ref(ref int r)
{
r = 0;
}
private void Out(out int o)
{
o = 0;
}
}
public class AsteroidsController : MonoBehaviour
{
public GameObject asteroidFieldPrefab;
private GameObject[] asteroids;
public void SpawnAsteroids(GameObject star, AsteroidBelt[] asteroidBelts)
{
asteroids = new GameObject[asteroidBelts.Length];
for (int i = 0; i < asteroids.Length; i++)
{
AsteroidBelt ast = asteroidBelts[i];
asteroids[i] = (GameObject) Instantiate(asteroidFieldPrefab, new Vector3(0, 0, 0), Quaternion.identity);
//Поскольку система изначально имеет радиус 1, она начинает спавнить астероиды внутри звезды. Не надо так
asteroids[i].SetActive(false);
asteroids[i].name = ast.name;
asteroids[i].transform.localScale *= Units_class.MetersToUnityUnits(ast.radius);
//А теперь надо
asteroids[i].SetActive(true);
AsteroidFieldOrbiter_script orbScript = asteroids[i].GetComponent<AsteroidFieldOrbiter_script>();
orbScript.astdField = ast;
orbScript.star = star;
orbScript.SetStartPosit();
}
}
}
Shader "Lines/Colored Blended"
{
SubShader
{
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off Cull Off Fog { Mode Off }
BindChannels { Bind "vertex", vertex Bind "color", color }
}
}
}