jump

1. Audio playback

  PlayOneShot :

 1 public class ExampleClass : MonoBehaviour
 2 {
 3     public AudioClip impact;
 4     AudioSource audioSource;
 5 
 6     void Start()
 7     {
 8         audioSource = GetComponent<AudioSource>();
 9     }
10 
11     void OnCollisionEnter()
12     {
13         audioSource.PlayOneShot(impact, 0.7F);
14     }
15 }

   There are also Play(), Stop() functions.

 

2. Particle effects

  

  Common functions: Play(), Stop(), Pause()

 

 3. Generate bricks (random direction. random distance, random size, random color)

1  // Add brick 
2  public  void CreateBrick()
 3  {
 4      int randomDir = Random.Range( 0 , 2 );
 5      brickDir = ((randomDir == 0 ) ? new Vector3( 1 , 0 , 0 ) : new Vector3 ( 0 , 0 , 1 ));              // Randomly generate direction 
6      float distance = Random.Range( 5.0f , 10.0f );                                              // Random distance7 
float scale = Random.Range( 2.0f      , 5.0f ) ;                                                      // Random size8      Color color = new Color(Random.Range(0f, 1 ), Random.Range(0f, 1 ), Random. Range(0f, 1 ));      // Random color
 9 // Generate brick 10      GameObject itemGo = GameObject.Instantiate(brickPreafab, currentBrick.transform.position + brickDir * distance, Quaternion.identity);
 11      itemGo.transform.localScale = new
     
 Vector3(scale, 2f, scale);
12     itemGo.GetComponent<MeshRenderer>().material.color = color;
13     lastBrick = itemGo;
14 }

 

 

4. Rigid body applies force

  AddForce function.

1  public  void AddForce(Vector3 force, ForceMode mode = ForceMode.Force);

  ForceMode:

  

 

 5. Camera Follow (Interpolation)

1  void LateUpdate()
 2  {
 3      MoveCamera();                // Move the camera 
4  }
 5  
6  // Move the camera 
7  private  void MoveCamera()
 8  {
 9      if (isMoveCamera)                // The camera moves with the player 
10      {
 11          Vector3 targetPos = relativeOffestWithCamera + this .transform.position;         // The current camera position 
12          Vector3 startPos = Camera.main.transform.position;
 13         Camera.main.transform.position = Vector3.Lerp(startPos, targetPos, 0.3f );       // interpolate 
14          if (Vector3.Distance(targetPos, Camera.main.transform.position) < 0.1f )         // reach target position 
15          {
 16              isMoveCamera = false ;
 17          }
 18      }
 19 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324401156&siteId=291194637