Guest User

Untitled

a guest
Jun 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class creatingobjectslist : MonoBehaviour {
  6.  
  7. public GameObject TargetPrefab;
  8.  
  9. void Start () {
  10. for (int i = 0; i < 5; i++){
  11. Instantiate(TargetPrefab, new Vector3(i * 1.5f, 0f, 0f), Quaternion.identity);
  12. TargetPrefab.name = "Ben" +i;
  13. }
  14. }
  15. }
  16.  
  17. using UnityEngine;
  18. using System.Collections;
  19. public class MoveCubeTogrid : MonoBehaviour {
  20. UnityEngine.AI.NavMeshAgent agent;
  21.  
  22. void Start () {
  23. agent = GetComponent< UnityEngine.AI.NavMeshAgent >();
  24. }
  25.  
  26. void Update () {
  27. if (Input.GetMouseButtonDown(0)) {
  28. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  29. RaycastHit hit;
  30.  
  31. if (Physics.Raycast(ray, out hit, Mathf.Infinity)) {
  32. //agent.destination = hit.point;
  33. agent.destination = GameObject.Find("Ben0").transform.position;
  34. }
  35. }
  36. }
  37. }
  38.  
  39. NullReferenceException: Object reference not set to an instance of an object
  40.  
  41. TargetPrefab.name = "Ben" +i;
Add Comment
Please, Sign In to add comment