Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class creatingobjectslist : MonoBehaviour {
- public GameObject TargetPrefab;
- void Start () {
- for (int i = 0; i < 5; i++){
- Instantiate(TargetPrefab, new Vector3(i * 1.5f, 0f, 0f), Quaternion.identity);
- TargetPrefab.name = "Ben" +i;
- }
- }
- }
- using UnityEngine;
- using System.Collections;
- public class MoveCubeTogrid : MonoBehaviour {
- UnityEngine.AI.NavMeshAgent agent;
- void Start () {
- agent = GetComponent< UnityEngine.AI.NavMeshAgent >();
- }
- void Update () {
- if (Input.GetMouseButtonDown(0)) {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, Mathf.Infinity)) {
- //agent.destination = hit.point;
- agent.destination = GameObject.Find("Ben0").transform.position;
- }
- }
- }
- }
- NullReferenceException: Object reference not set to an instance of an object
- TargetPrefab.name = "Ben" +i;
Add Comment
Please, Sign In to add comment