Unity tools

From DreamsteepWiki

Jump to: navigation, search


unity_ai


var tex :texture;



BOUNCE IDEA


function OnCollisionEnter (collisionInfo : Collision) {
   
  // print (collisionInfo.gameObject.tag) ; //??? HTH DO I TAG?

  // print (collisionInfo.gameObject.transform.position) ;
  
  
   
  // if (collisionInfo.gameObject.tag=="sphere"){

     var rand: int = Random.Range(-200,200);
    collisionInfo.gameObject.rigidbody.AddForce(Vector3.up*500);
    collisionInfo.gameObject.rigidbody.AddForce(Vector3.right*rand);   
   //}
   

}


SmoothLookAt

var target : Transform;
var damping = 6.0;
var smooth = true;

@script AddComponentMenu("Camera-Control/Smooth Look At")

function LateUpdate () {
	if (target) {
		if (smooth)
		{
			// Look at and dampen the rotation
			var rotation = Quaternion.LookRotation(target.position - transform.position);
			transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
		}
		else
		{
			// Just lookat
		    transform.LookAt(target);
		}
	}
}

function Start () {
	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}



Smooth Follow

/*
This camera smoothes out rotation around the y-axis and height.
Horizontal Distance to the target is always fixed.

There are many different ways to smooth the rotation but doing it this way gives you a lot of control over how the camera behaves.

For every of those smoothed values we calculate the wanted value and the current value.
Then we smooth it using the Lerp function.
Then we apply the smoothed values to the transform's position.
*/

// The target we are following
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 5.0;
// How much we 
var heightDamping = 2.0;
var rotationDamping = 3.0;

// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Smooth Follow")


function LateUpdate () {
	// Early out if we don't have a target
	if (!target)
		return;
	
	// Calculate the current rotation angles
	wantedRotationAngle = target.eulerAngles.y;
	wantedHeight = target.position.y + height;
		
	currentRotationAngle = transform.eulerAngles.y;
	currentHeight = transform.position.y;
	
	// Damp the rotation around the y-axis
	currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

	// Damp the height
	currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

	// Convert the angle into a rotation
	currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
	
	// Set the position of the camera on the x-z plane to:
	// distance meters behind the target
	transform.position = target.position;
	transform.position -= currentRotation * Vector3.forward * distance;

	// Set the height of the camera
	transform.position.y = currentHeight;
	
	// Always look at the target
	transform.LookAt (target);
}



Make a particle explosion when bullets hit


var explody_pf :Transform;


function explody (){

            var instancedbullet =Instantiate( explody_pf ,transform.position,Quaternion.identity);
	         //instancedbullet.rigidbody.AddForce(transform.forward * shootForce);

}

			 
function OnCollisionEnter (collisionInfo : Collision) {
   
  // print (collisionInfo.gameObject.tag) ; //??? HTH DO I TAG?
  // if (collisionInfo.gameObject.tag=="sphere"){
  //
  // print (collisionInfo.gameObject.transform.position) ;

  explody();

     var rand: int = Random.Range(-200,200);
    collisionInfo.gameObject.rigidbody.AddForce(Vector3.up*1500);
    collisionInfo.gameObject.rigidbody.AddForce(Vector3.right*rand);   
	
   //}
   

}
function OnCollisionEnter (collisionInfo : Collision) {
   if (collisionInfo.gameObject.tag=="sphere"){
    var rand: int = Random.Range(-200,200);
    collisionInfo.gameObject.rigidbody.AddForce(Vector3.up*500);
    collisionInfo.gameObject.rigidbody.AddForce(Vector3.right*rand);   
   }
   

}






Junk , destroy object , untested

var prefab : Transform;

function Start () {
   var clone  = Instantiate (prefab, Vector3(transform.position.x,
   transform.position.y,
   transform.position.z),
   Quaternion.identity);
}


function Update () {
   transform.Rotate(Vector3.up * Time.deltaTime*50);
   transform.Rotate(Vector3.right * Time.deltaTime*50);
}


function OnTriggerEnter(collisionInfo : Collider){
      Destroy (clone); // <======= THE ERROR IS THIS LINE
      Destroy (gameObject);
      //  Destroy(collisionInfo.gameObject);
}