About Components (How to):-
- Create a new project with 2D mode as shown below image.
- First Create Empty Game Object and rename it 'ArrowImage' at Hierarchy.
- Add Component 'Sprite Renderer' at Inspector.
- Import arrow image from your Window/Mac Desktop at project folder and drop it to sprite field.
- Add Component 'Rigidbody 2D' at inspector of your arrow.
- Save Scene and drop 'Arrow Object' to Project folder. Now it's convert into a prefab.
- Delete your 'ArrowImage' at Hierarchy
- Create Spawn point (where you want to release your arrow.. Probably from bow )
- Add Component 'bolow script (InstantiateScript)' to spawnPoint.
- Browse ArrowImage Prefab for InstantiateScript.
- Play your scene... Click on you Game View.
About Script Tips:-
1. You should use LateUpdate(){} for physics iterations.
Script : -
using UnityEngine;
using System.Collections;
public class InstantiateScript : MonoBehaviour {
public Rigidbody2D arrow1;
public int Force = 9000;
void LateUpdate () {
if (Input.GetButtonDown("Fire1")) {
Rigidbody2D arrowRig2D;
arrowRig2D = Instantiate(arrow1, transform.position, transform.rotation) as Rigidbody2D;
arrowRig2D.AddForce(-transform.right * Force * Time.deltaTime);
}
}
}
using System.Collections;
public class InstantiateScript : MonoBehaviour {
public Rigidbody2D arrow1;
public int Force = 9000;
void LateUpdate () {
if (Input.GetButtonDown("Fire1")) {
Rigidbody2D arrowRig2D;
arrowRig2D = Instantiate(arrow1, transform.position, transform.rotation) as Rigidbody2D;
arrowRig2D.AddForce(-transform.right * Force * Time.deltaTime);
}
}
}
if you want to decrease image size at unity... you should increase Pixel Per Unit image import Settings as shown below image
No comments:
Post a Comment