init
This commit is contained in:
commit
9afd57306d
323 changed files with 204673 additions and 0 deletions
42
Assets/Scripts/Game13/Game13.cs
Normal file
42
Assets/Scripts/Game13/Game13.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Game13 : MonoBehaviour{
|
||||
|
||||
public GameObject enemy;
|
||||
public Transform target;
|
||||
public float speed;
|
||||
bool canMove = true;
|
||||
Vector3 start, end;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
enemy.transform.position = new Vector2(-2, Random.Range(3.5f, -3.5f));
|
||||
if (target != null){
|
||||
target.parent = null;
|
||||
start = transform.position;
|
||||
end = target.position;
|
||||
}
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (Input.GetKeyDown(KeyCode.Space)){
|
||||
canMove = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate(){
|
||||
if (target != null){
|
||||
if (canMove){
|
||||
float fixedSpeed = speed * Time.fixedDeltaTime;
|
||||
transform.position = Vector3.MoveTowards(transform.position, target.position, fixedSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
if (transform.position == target.position){
|
||||
target.position = (target.position == start) ? end : start;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue