Unity3D 2.2

How to construct a preform (Prefab)?

Select the object you need as a preform

Inside onto Assets

How to remove the script file object mount?

In the component tray operation

Alt + left mouse button, right mouse button to change viewing angle can be achieved

 

Box

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Jump : MonoBehaviour {

	public float jumpspeed = 5.0f;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetMouseButtonDown (0)) {// 0 是鼠标左键 1 是鼠标右键
			//this.GetComponent<Transform> ().position += new Vector3 (0.0f, 1.0f, 0.0f);
			this.GetComponent<Rigidbody>().velocity = Vector3.up * jumpspeed;//乘上系数的目的是放大幅度
		}
	}
}

Ball

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ball : MonoBehaviour {

	// Use this for initialization
	void Start () {
		this.GetComponent<Rigidbody> ().velocity = new Vector3 (-5.0f,-5.0f,0.0f);
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	void OnBecameInvisible(){
		Destroy (this.gameObject);
	}
}

LauncherPrefab

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Launch : MonoBehaviour {
	public GameObject ballPrefab; 
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetMouseButtonDown (1)) {
			Instantiate (this.ballPrefab);
		}
	}
}

LauncherPrefab assigned to ballPrefab in the component tray To Ball

Published 369 original articles · won praise 74 · views 80000 +

Guess you like

Origin blog.csdn.net/qq_41333844/article/details/104613830