GitHub - Endlessdaydream/Endless_Unity_Projects: Unity Projects of EndlessdaydramUnity Projects of Endlessdaydram. Contribute to Endlessdaydream/Endless_Unity_Projects development by creating an account on GitHub.
https://github.com/Endlessdaydream/Endless_Unity_Projects

(37) How to make a 2D Bow and Arrow with UNITY & C#! - YouTube
https://www.youtube.com/watch?app=desktop&v=tNwLaGUJTK4
using System.Collections;
using System.Collections.Generic;
public class PlayerController : MonoBehaviour
if (Input.GetKeyDown(KeyCode.Tab))
if (Input.GetMouseButton(1))
if (Input.GetMouseButton(0))
if (Input.GetMouseButtonUp(0))
player.Move(Input.GetAxisRaw("Horizontal"));
if (Input.GetButtonDown("Jump"))
using System.Collections;
using System.Collections.Generic;
public class PlayerCharacter : MonoBehaviour
public float jumpSpeed = 14;
public float minShootSpeed = 5f, maxShootSpeed = 24f;
public Transform shootPoint;
public Transform flagPoint;
public List arrowsPrefab;
public float maxStoreTime = 2f;
bool isStopShoot = false;
public static PlayerCharacter Instance { get; private set; }
points = new Transform[30];
points[i] = Instantiate(flagPoint, transform);
var render = points[i].GetComponent();
temp.a *= (float)(points.Length - i) / points.Length;
foot1 = transform.Find("foot1");
foot2 = transform.Find("foot2");
center = transform.Find("center");
GameObject canvas = GameObject.Find("Canvas");
gameOverPanel = canvas.transform.Find("GameOverPanel");
gameOverPanel.gameObject.SetActive(false);
completePanel = canvas.transform.Find("CompletePanel");
completePanel.gameObject.SetActive(false);
private void FixedUpdate()
LayerMask layerMask = ~(1 << 7);
if (Physics2D.Raycast(foot1.position, Vector2.down, 0.25f, layerMask) || Physics2D.Raycast(foot2.position, Vector2.down, 0.25f, layerMask))
if (curArrowId == 1 && curArrow)
line.SetPosition(0, center.position);
line.SetPosition(1, curArrow.position);
var dir = (curArrow.position - center.position).normalized;
Transform linkObj = curArrow.parent;
if(linkObj.GetComponent())
Rigidbody2D otherR = linkObj.GetComponent();
otherR.AddForce(-dir * 20f);
public void PrepareShoot()
curStoreTime += Time.deltaTime;
shootSpeed = minShootSpeed + (maxShootSpeed - minShootSpeed) * (Mathf.Min(curStoreTime, maxStoreTime) / maxStoreTime);
if (isGround) r.velocity = new Vector2(0, r.velocity.y);
curArrow = Instantiate(arrowsPrefab[curArrowId], shootPoint.position, shootPoint.rotation);
curArrow.GetComponent().velocity = shootSpeed * curArrow.right;
Destroy(curArrow.gameObject);
float deltaTime = time / points.Length;
Vector2 v0 = shootPoint.right * shootSpeed;
Vector2 start = shootPoint.position;
for (int i = 0; i < points.Length; i++)
points[i].position = start + v0 * t + 0.5f * Physics2D.gravity * arrowsPrefab[curArrowId].GetComponent().gravityScale * t * t;
void ShowPoints(bool isShow)
for (int i = 0; i < points.Length; i++)
points[i].gameObject.SetActive(isShow);
public void Move(float h)
transform.right = h < 0 ? Vector2.left : Vector2.right;
r.velocity = new Vector2(h * speed, r.velocity.y);
r.AddForce(new Vector2(h * 30 * Time.deltaTime / Time.fixedDeltaTime, 0));
r.velocity = new Vector2(Mathf.Clamp(r.velocity.x, -speed, speed), r.velocity.y);
if (!isGround||isAim) return;
r.velocity = new Vector2(r.velocity.x, jumpSpeed);
anim.SetBool("isWalk", Mathf.Abs(r.velocity.x) > 0.01f);
anim.SetBool("isGround", isGround);
anim.SetBool("isFall", r.velocity.y < 0.01f);
anim.SetBool("isAim", isAim);
gameOverPanel.gameObject.SetActive(true);
StartCoroutine(TempTurnRed());
completePanel.gameObject.SetActive(true);
IEnumerator TempTurnRed()
render.color = Color.red;
yield return new WaitForSeconds(0.1f);
render.color = Color.white;
using System.Collections;
using System.Collections.Generic;
public class Bow : MonoBehaviour
private void LateUpdate()
Vector2 dir = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
using System.Collections;
using System.Collections.Generic;
public class ArrowBase : MonoBehaviour
public Transform hitObj = null;
private void OnTriggerEnter2D(Collider2D collision)
if (transform.parent) return;
r.velocity = Vector2.zero;
transform.parent = collision.transform;
if (transform.parent) return;
float angle = Mathf.Atan2(r.velocity.y, r.velocity.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0, angle);
using System.Collections;
using System.Collections.Generic;
public class Bee : MonsterBase
public Rigidbody2D bulletPrefab;
bool isOpenAttack = false;
var bound = transform.parent.Find("Bound");
shootPoint = transform.Find("ShootPoint");
range.size = bound.localScale;
range.center = bound.position;
StartCoroutine(RandomMove(RandomTarget()));
private new void Update()
if(isVigilant&&!isOpenAttack&&!isDead)
StartCoroutine(AutoAttack());
IEnumerator RandomMove(Vector2 target)
while (Vector2.Distance(transform.position, target) > 0.1f && !isDead)
if (isVigilant && player)
transform.right = player.position.x < transform.position.x ? Vector2.right : Vector2.left;
transform.right = target.x < transform.position.x ? Vector2.right : Vector2.left;
transform.position = Vector2.MoveTowards(transform.position, target, 3f * Time.deltaTime);
yield return new WaitForSeconds(1f);
while(this&&player&&!isDead)
var r = Instantiate(bulletPrefab, shootPoint.position, Quaternion.identity);
r.velocity = (player.position - r.transform.position).normalized * 2f;
yield return new WaitForSeconds(3f);
return new Vector2(Random.Range(range.xMin, range.xMax), Random.Range(range.yMin, range.yMax));

using System.Collections;
using System.Collections.Generic;
public class Flower : MonsterBase
private void FixedUpdate()
LayerMask layerMask = 1 << 7;
if (Physics2D.Raycast(transform.position-new Vector3(0,0.3f), transform.right, 0.7f, layerMask))
anim.SetTrigger("attack");
r.velocity = Vector2.zero;
LayerMask layerMask = 1 << 7;
var hitInfo = Physics2D.Raycast(transform.position - new Vector3(0, 0.3f), transform.right, 0.8f, layerMask);
hitInfo.transform.GetComponent
().beHurt(); private new void Update()
if (!isDead && !stopMove && isVigilant && player)
bool isLeft = player.position.x < transform.position.x;
transform.right = isLeft ? Vector2.left : Vector2.right;
r.velocity = new Vector2(isLeft ? -2 : 2, r.velocity.y);
using System.Collections;
using System.Collections.Generic;
public class MonsterBase : MonoBehaviour
protected Transform player;
protected bool isDead = false, isVigilant = false;
player = GameObject.FindWithTag("Player").transform;
if (player&&Vector2.Distance(player.position, transform.position) < 5f)
private void OnTriggerEnter2D(Collider2D collision)
if (collision.gameObject.layer == 8)
r.constraints = RigidbodyConstraints2D.None;
render.color = new Color(0.5f, 0.5f, 0.5f, 1);
bool isLeft = transform.position.x - player.position.x >= 0;
r.AddForce(new Vector2(isLeft ? 1 : -1, 1) * 200f);
Destroy(transform.root.gameObject, 2f);
StartCoroutine(TempTurnRed());
IEnumerator TempTurnRed()
render.color = Color.red;
yield return new WaitForSeconds(0.1f);
render.color = Color.white;

using System.Collections;
using System.Collections.Generic;
public class Cup : MonoBehaviour
private void OnTriggerEnter2D(Collider2D collision)
if (collision.gameObject.layer == 8)
PlayerCharacter.Instance.Win();
(37) How to make an AWESOME fully INTERACTIVE Game Menu in UNITY - Everything you need to know. - YouTube
https://www.youtube.com/watch?v=pGxI8_GYfUY
using System.Collections;
using System.Collections.Generic;
public class uisettingscript : MonoBehaviour
Panel.GetComponent
().SetTrigger("Pop"); Application.OpenURL("https://assetstore.unity.com/");
using System.Collections;
using System.Collections.Generic;
public delegate void AudioCallBack();
[RequireComponent(typeof(AudioSource))]
public class Audio : MonoBehaviour
public AudioClip audiodata(string name)
return Resources.Load
("Audios/" + name); public static Audio Instance;
ClipData clipdata = new ClipData();
public AudioSource _audioSource;
_audioSource = GetComponent
(); public void AudioPlay(string name)
_audioSource.clip = clipdata.audiodata(name);
public void AudioUnPause()
public void AudioSwitch(string name)
AudioClip _clip = clipdata.audiodata(name);
if (_audioSource.isPlaying)
_audioSource.clip = _clip;
public void AudioPlayer(string name, AudioCallBack callback)
_audioSource.clip = clipdata.audiodata(name);
StartCoroutine(AudioDelayedCallBack(_audioSource.clip.length, callback));
public void AudioPlayer(string name, AudioCallBack callback, float time)
_audioSource.clip = clipdata.audiodata(name);
StartCoroutine(AudioDelayedCallBack(_audioSource.clip.length + time, callback));
IEnumerator AudioDelayedCallBack(float time, AudioCallBack callback)
yield return new WaitForSeconds(time);
public void AudioDelayPlay(string name, float time)
_audioSource.clip = clipdata.audiodata(name);
Invoke("AudioDelayTime", time);
public void AudioDelayTime() { _audioSource.Play(); }
public void AudioInstantiate(string name)
GameObject obj = new GameObject();
AudioSource _audio = obj.AddComponent
(); _audio.name = "AudioSource";
_audio.playOnAwake = true;
_audio.clip = clipdata.audiodata(name);
StartCoroutine(AudioFinish(_audio.clip.length, obj));
IEnumerator AudioFinish(float time, GameObject obj)
yield return new WaitForSeconds(time);
public void AudioAtPoint(string name, Vector3 CameraPos)
AudioSource.PlayClipAtPoint(clipdata.audiodata(name), CameraPos, 1.0f);
public void AudioSourceOther(GameObject obj, string name)
AudioSource audioSource = obj.GetComponent
(); audioSource.clip = clipdata.audiodata(name);
_audioSource.clip = null;

场景切换

using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
public class TOBOSS : MonoBehaviour
SceneManager.LoadScene("BOSS");
DontDestroyOnLoad
using System.Collections;
using System.Collections.Generic;
public class BackgroundMusic : MonoBehaviour
static BackgroundMusic S;
DontDestroyOnLoad(gameObject);