public float speed = 5;
private bool isFly = False;
void Start(){
startPoint = GameObject.Find("startPoint").transform;
}
void Update(){
is(isFly == false)
{
}
}
public float speed = 5;
private bool isFly = False;
void Start(){
startPoint = GameObject.Find("startPoint").transform;
}
void Update(){
is(isFly == false)
{
}
}
//定义针的移动位置
private Transform startPoint;
private Transform spawnPoint;
//放置针的位置
public GameObject pinPrefab;
void Start(){
startPoint = GameObject.Find("startPoint").transform;
spawnPoint =
GameObject.Find("SpawnPoint").transform;
spawnPin();
}
void SpawnPin()
{
GameObject.Instantiate(pinPrefab,spawnPoint.position,pinPrefab.transform.rotation)
}
给针头加上碰撞器材料
r任务5:控制小球旋转
//在定义中定义速度是90
public float speed = 90;
// Update里设置旋转速度是90
void Update(){
transform.Rotate(new Vector3(0,0,speed*Time.deltaTime));
}
需要先把针实例化到屏幕外面,为a点,然后针从a点生成后移动到B点预备发射。因此需要先创建两个空物体,第一个为开始的点a,新建为starpoint。第二个为预备点b,新建spawnpoint。这两个空物体坐标s需要设置为0,当有了这两个空物体就可以实现针的实例化。我们需要创建一个gamemanager去管理这两个空物体。接下来要在gamemanager里得到starpoint和spawnpoint两个点的坐标,可以通过键入代码实现。实现代码如下
cha
旋转:
public class RotateSelf : MonoBehaviour
{
public float Speed = 90;
// Update is called once per frame
void Update()
{
transform.Rotate(new Vector3(0,0,-Speed * Time.deltaTime));
}
}
控制针移动到就位位置
添加脚本Pin控制针的运动
开发GameManager去生成针
控制针的发射,1、实例化的位置,2、针开始发射的位置
创建两个空物体,1、StartPoint
将PIn放在StartPoint下面,复制StartPoint
开发针的Prefab预制体
将素材Pin拖进场景里,调整大小、位置和颜色,y轴旋转九十度
给针头添加圆形碰撞器
控制小球旋转
1、创建脚本RotateSelf,放在circle下
开发旋转的小球和分数显示
1、将图片circle导入场景
2、调整circle位置,使其居中,x轴为0,修改颜色和大小
显示分数:UI-text,UI太大,因为UI是按照像素来设置的,一像素相当一米。删除eventsystem,进入Reset,字体居中为白色,text:0,字体大小调大
调整canvas大小使其与text一样
1、新建一个StickPinProject的2D项目
2、导入素材
3、分别创建Frefabs和Scripts等文件夹
4、改变main camera的背景颜色-backg
RotateSelf
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateSelf : MonoBehaviour
{
public float speed = 90;
// Update is called once per frame
void Update()
{
transform.Rotate(new Vector3(0, 0, -speed * Time.deltaTime));// 控制小球旋转,
}
}
GameObject
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
private Transform startPoint;
private Transform spawnPoint;
public GameObject pinPrefab;
// Start is called before the first frame update
void Start()
{
startPoint = GameObject.Find("StartPoint").transform;
spawnPoint = GameObject.Find("SpawnPoint").transform;
SpawnPin();
}
void SpawnPin()//对针的实例化
{
GameObject.Instantiate(pinPrefab, spawnPoint.position, pinPrefab.transform.rotation);
}
}
11111
StartPoint
SpawnPoint
GameManger
private Transform startPoint
pinPrefab
Vector3.MoveTowards(我的位置,目的地位置,速度(speed*Time.deltaTime))
2D:
transform.Rotate(x,y,角度);