One: (Collision body) Trigger Information detection:
The two objects that collide should meet the conditions:
NO1: Both bodies should have colliding bodies.
NO2: One with a rigid body;
NO3: The script that detects the triggering information needs to be bound to an object with a rigid body
1.monobehaviour.oncollisionenter (Collision Collisioninfo) when entering the collider
2.monobehaviour.oncollisionexit (Collision Collisioninfo) when exiting the collider
3.monobehaviour.oncollisionstay (Collision Collisioninfo) as a stay collider
Get Material color
Public cube1;//script tied to CUBE1, collider
Public Cube2;//cube2 objects that collide and move
public render rend;
void Start ()
{
Gets the component of the current object
rend = getcomponent<renderer> ();
}
void Oncollisionenter (Collision collisioninfo)
{
Debug.Log (Gameobject.name);
Cube2 Get material Yellow collisioninfo.gameobject.getcomponent<renderer> (). Material.color = Color.yellow;
Cube2.transform.Translate (vector3.down *2f * time.deltatime);
}
void Oncollisionstay (Collision collisioninfo)
{
Debug.Log (Collisioninfo.gameobject);
Cube.position = Vector3.movetowards (new Vector3 (3,2,0), New Vector3 (3,5,0), 2f);
Cube.transform.Translate (Vector3.forward * 2f);
Cube.transform.Translate (Vector3.right*0.5f*time.deltatime);
Rend.material.color = Color.Blue;
Cube1 Gets the color blue
}
void Oncollisionexit (Collision collisioninfo)
{
Debug.Log ("The collision is over!" ");
CUBE1 Get color to Black
Rend.material.color = Color.Black;
}
two: (trigger) Trigger Information Detection :
The two objects that collide should meet the conditions:
NO1: Both objects should have colliding bodies;
NO2: At least one rigid body collider is selected and the Istrigger check box is checked, and the other has a minimum of one collider component;
NO3: The script that detects collisions must be attached to the trigger with a rigid body;
1.monobehaviour.ontriggerenter (Collider Other) when entering the trigger
2.monobehaviour.ontriggerexit (Collider Other) when exiting a trigger
3.monobehaviour.ontriggerstay (Collider Other) when stay trigger
Three: Load Scene
Using Unityengine.scenemanagement;
Scenemanager.loadscene ("Simulation training Scene");
Four: mouse follow (coordinate conversion)
canvas canvas;
Recttransform Recttransform;
Vector2 POS;
Vector3 result;
void Start ()
{
Recttransform = transform as recttransform;
canvas = gameobject.find ("Canvas"). Getcomponent<canvas> ();
}
void Update ()
{
if (Recttransformutility.screenpointtolocalpointinrectangle (Canvas.transform as Recttransform, Input.mousePosition , Canvas.worldcamera, out POS))
{
Recttransform.anchoredposition = pos;
Recttransform.parent = Canvas.transform;
}
}
Five: Toggle Add monitoring
Public Gameobject Tog3;
Tog3.getcomponent<toggle> (). Onvaluechanged.addlistener (delegate
{
This. OnClick (TOG3);
});
void OnClick (Gameobject tog)
{
}
Six: Text label display:
Public list<gameobject> toolpic=new list<gameobject> ();
Public list<gameobject> toolpicname = new list<gameobject> ();
void Start ()
{
for (int i = 0; i < Toolpic.count; i++)
{
Eventtriggerlistener.get (Toolpic[i]). OnEnter + = Onmouseenterimage;
Eventtriggerlistener.get (Toolpic[i]). OnExit + = Onmouseexitimage;
}
}
void Onmouseenterimage (Gameobject btn)
{
for (int i = 0; i < Toolpic.count; i++)
{//display the corresponding text according to the picture
if (btn = = Toolpic[i])
{
Toolpicname[i]. SetActive (TRUE);
}
}
}
void Onmouseexitimage (Gameobject btn)
{
for (int i = 0; i < Toolpic.count; i++)
{
if (btn = = Toolpic[i])
{
Toolpicname[i]. SetActive (FALSE);
}
}
}
Seven:3D object 360 degree rotation
public Transform target;
public float speed = 1f;
void Start ()
{
if (target = = null) target = transform;
}
public void Ondrag (Pointereventdata eventData)
{
Method One:
Target.localeulerangles = new Vector3 (0f, Target.localeulerangles.y + eventdata.position.y-y, 0f);
y = eventdata.position.y;
Method Two:
Target.localrotation = Quaternion.euler (0f, -0.5f * eventdata.delta.x * speed, 0f) * target.localrotation;
}
public void Onbegindrag (Pointereventdata eventData)
{
y = eventdata.position.y;
}
Ugui Essentials Summary